Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3323826
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T23:20:55+00:00 2026-05-17T23:20:55+00:00

Which annotation, @Resource ( jsr250 ) or @Autowired (Spring-specific) should I use in DI?

  • 0

Which annotation, @Resource (jsr250) or @Autowired (Spring-specific) should I use in DI?

I have successfully used both in the past, @Resource(name="blah") and @Autowired @Qualifier("blah")

My instinct is to stick with the @Resource tag since it’s been ratified by the jsr people.
Anyone has strong thoughts on this?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-17T23:20:55+00:00Added an answer on May 17, 2026 at 11:20 pm

    In spring pre-3.0 it doesn’t matter which one.

    In spring 3.0 there’s support for the standard (JSR-330) annotation @javax.inject.Inject – use it, with a combination of @Qualifier. Note that spring now also supports the @javax.inject.Qualifier meta-annotation:

    @Qualifier
    @Retention(RUNTIME)
    public @interface YourQualifier {}
    

    So you can have

    <bean class="com.pkg.SomeBean">
       <qualifier type="YourQualifier"/>
    </bean>
    

    or

    @YourQualifier
    @Component
    public class SomeBean implements Foo { .. }
    

    And then:

    @Inject @YourQualifier private Foo foo;
    

    This makes less use of String-names, which can be misspelled and are harder to maintain.


    As for the original question: both, without specifying any attributes of the annotation, perform injection by type. The difference is:

    • @Resource allows you to specify a name of the injected bean
    • @Autowired allows you to mark it as non-mandatory.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

If I have a parametrized annotation which is used on a field, can the
I have a resource (Spring bean) which has some of its fields injected by
I have an custom annotation called @Pojo which I use for automatic wiki documentation
I'm trying to configure a class with Annotation based configuration in Spring 3, which
I have a mapview with several annotations. Every annotation has a leftCalloutAccessoryView which is
I have a webapp which is built using spring 3 and tiles 2 (not
I have a small Spring (3.1.0.RELEASE) application, which was working just fine, until I
I would like to use @Repository spring annotation to avoid adding bean in context.xml.
There is a property of type Resource in my Spring 3 bean that should
I have a scenario configuring Spring Security on embedded Jetty which seems to be

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.