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

  • Home
  • SEARCH
  • 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

I have a bean in which I've injected an HttpServletRequest using the @Autowired annotation
Which is better? Or use and OR mapper with SP's? If you have a
I would like to use @Repository spring annotation to avoid adding bean in context.xml.
Which is more correct? This (with the @Autowired annotation on the method)? @Controller public
Which graduate program should I choose – SUNY Buffalo or SUNY Binghamton?
Which of the following has the best performance? I have seen method two implemented
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'testController': Injection of resource dependencies failed; nested exception
Which is the best PHP Annotation library out there? Thanks
I want to execute test methods which are annotated by @Test in specific order.
Which Database table Schema is more efficient and why? Users (UserID, UserName, CompamyId) Companies

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.