Oct 19th, 2009, 09:46 AM
Now that JSR 330, Dependency Injection for Java, written by Bob Lee of Google Guice and Rod Johnson of SpringSource, has been approved, what is SpringSource's recommendation on writing DI code in the future? Should we transition toward using the new annotations?
Oct 22nd, 2009, 06:53 AM
I'm no longer a SpringSource employee, but I am a core Spring developer. So hopefully you won't mind my input.
I feel that the choice between Spring-specific and JSR-330 DI annotations is really just a matter of personal preference. Some people prefer to "stick to standards", while others don't mind having dependencies on Spring in their code.
If you have existing projects which use Spring's DI annotations, I personally wouldn't bother migrating those. For new projects, you might prefer @Inject and @Inject/@Named instead of @Autowired and (Spring's) @Qualifier, respectively.
Of course, the JSR-330 annotations offer a subset of the features provided by Spring's annotation-driven configuration support. So there will be times when you are required to use Spring's annotations to benefit from Spring's advanced configuration options. Contrast this discussion with the "JPA vs. Hibernate" discussion: JPA offers a subset of the Hibernate ORM support.
In summary, for new projects, consider using JSR-330 annotations where applicable, but don't be afraid to mix and match if you need Spring-specific configuration options.
Oct 22nd, 2009, 10:50 AM
The problem with standards
The problem with standards is that there's too many of them.
Seriously, my project is converging on a Spring/GWT solution. Spring wants me to use Spring DI on the server side, and GWT wants me to use Google Guice/GIN on the client side. I was hoping that JSR 330 would be motivation for the two sides' DI techniques to converge. Hybrid vigor, as it were.
I know there are projects to allow Spring-ish DI on the client side, but they're not well-supported.
Tags for this Thread