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
I have a preference for @Autowired, because it's fast and easy, that's my opinion!
Jeux de sport
Last edited by lewisa; Jan 21st, 2011 at 07:46 AM.
I have prefered @autowired
@Autowired ties your code to Spring. Using @Inject, you can run your code on Spring, Weld SE, Java EE 6, Guice, ...
So don't use @Autowired if you want to be flexible.
Regards,
Harald
@Inject on new project.