View Poll Results: Which Dependency Injection annotation do you favor?

Voters
132. You may not vote on this poll
  • @Inject

    30 22.73%
  • @Autowired

    85 64.39%
  • I don't use either.

    17 12.88%
Results 1 to 10 of 24

Thread: Which Dependency Injection annotation do you favor?

Hybrid View

  1. #1
    Join Date
    Aug 2004
    Location
    Melbourne, FL
    Posts
    2,794

    Default Which Dependency Injection annotation do you favor?

    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

  2. #2
    Join Date
    Nov 2009
    Location
    Montreal, Quebec
    Posts
    398

    Default

    @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.

  3. #3
    Join Date
    Jul 2010
    Location
    Venice, Italy
    Posts
    709

    Default

    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...

  4. #4

    Thumbs up

    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.

  5. #5
    Join Date
    Dec 2010
    Location
    Singapore
    Posts
    287

    Default

    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/

  6. #6

    Default

    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

  7. #7
    Join Date
    Jul 2009
    Posts
    16

    Default

    @Resource is even better ! JEE5 compliant and Spring non intrusive code .

  8. #8

    Default I am a @Autowired Fan!

    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

  9. #9
    Join Date
    Nov 2006
    Location
    Boston, MA
    Posts
    303

    Default @Atutowired

    @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?

  10. #10

    Default

    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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •