It's been awhile since we did one of these...
Which dependency injection annotation do you favor?
1. @Inject
2. @Autowired
3. I don't use either.
Voting period closes in 2 weeks.
@Inject
@Autowired
I don't use either.
It's been awhile since we did one of these...
Which dependency injection annotation do you favor?
1. @Inject
2. @Autowired
3. I don't use either.
Voting period closes in 2 weeks.
Keith Donald
Core Spring Development Team
@Inject does have the advantage of being a JSR, so it can be used without the Spring framework, although how widely is it used or known of? I first saw it used in a GemFire demo not long ago I believe, and then once again at S2GX. I have not used it myself (yet). I think for users new to the Spring framework and DI in general, they'll probably use @Autowired based on what they learn in the Spring documentation or tutorials. Would be great to see some kind of blog post comparing the equivalent use of both.
I voted for @Autowired, because I learned to use it and love it, and I wouldn't like to be forced to switch. Even if @Inject comes from a jsr specification (thus decoupling even more your application from the Spring framework) I don't see it as an issue (at least in the immediate future) since there really isn't, up to now, a good DI-based framework that can offer what Spring offers.
Also, regarding jsr, since the Oracle acquisition my faith in the jcp has slowly begun to fade...but that is another matter...
as rightly said by pgrimard, i recently started using annotation based DI and @Autowired is the first style that came naturally...
i really liked easy of use and speed of development using @autowired.
Have never used @Inject, so voted for @Autowired. But @Inject has an advantage of being a jsr. By the way very recently only i found this annotation.
http://matthiaswessendorf.wordpress....e-jsr-330-way/
i prefer @Inject i have used it for a long time and everything goes well about it using it can let you have less problems so i like it very much
@Resource is even better ! JEE5 compliant and Spring non intrusive code.
Autowired has always worked for me, it's clean, simple, and does exactly what I need it to.
Paul
Find Spring Consultants at java316.com
@Autowired can be configured to NOT require the injection, therefore it is more functional and flexible than @Inject. So, I always use @Autowired, and I am not concerned about being tied to Spring... C'mon people, are you serious?![]()
Autowiring is fine up to a point:
- where contexts are small, self-contained and isolated
- when starting out and wanting to take defaults
However, with large systems with lots of config where you have to do things like re-use resources or use classpath* and/or imports then you can lose control of what's going on. As soon as you have to start using qualifiers you're going against the grain of autowiring anyway.
Admittedly, the above situations speak of poor layout, design and control of configuration. The config can and does get this way very quickly.
Autowiring does a good job and I'm often tempted to use it but when it breaks it's tough to sort out whereas being explicit rarely has these problems.