Java – is there a simple framework that allows dependency injection in stand-alone programs?
We basically need to be able to adjust the behavior at startup by providing the required classes generated by various factories in our application (to avoid the hard binding of "new" operators)
I know this is provided by several large frameworks, but I've been looking for something easy to use for a stand-alone Java application, not huge
Any suggestions?
Editor: in my experience, frameworks tend to become larger (and more complex) as they mature As part of the major refactoring (technical debt), I need to transform legacy applications, so simplification is crucial to the libraries used I don't mind some coding in our application, but it must be very obvious what happened AOP tends to move things away, which may make the application more difficult to maintain
Editor: we have now reached the point where we actually need to make a decision The application may exist for decades, so we need to make reversible decisions through a framework that can remain for a long time I really like the static type checking provided by Guice, but the annotation is not explicitly bound to Guice, not external like spring I also like the code to look more concise when using Guice instead of spring We need something powerful and useful We don't need any more di Is there a use case that clearly describes one of them?
Editor 2011-07-27: the final decision is to use jsr-330 API in the code and choose whether to use spring, Guice or weld on a project by project basis Guice works well in JSR - 330 implementation for stand - alone applications
Solution
Have you seen the Google Guice framework? It is very lightweight, annotation based, and avoids the use of XML configuration files
And Pico – and nano container (from codehaus). Although last time I seemed (undeniably a few years ago) to lack documents, they were quite lightweight
I must say that I agree with others. I think your assumption is that spring is huge and chaotic It is really a very simple IOC container and is worth recommending