I don’t see any difference between two ways, @Qualifier is always used with @Autowired.
@Autowired
@Qualifier("alpha")
VS
@Resource(name="alpha")
Anyone could let me know the difference? Thanks!
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
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.
@Autowiredcan be used alone . If it is used alone , it will be wired by type . So problems arises if more than one bean of the same type are declared in the container as@Autowireddoes not know which beans to use to inject. As a result , use@Qualifiertogether with@Autowiredto clarify which beans to be actually wired by specifying the bean name (wired by name)@Resourceis wired by name too . So if@Autowiredis used together with@Qualifier, it is the same as the@Resource.The difference are that
@Autowiredand@Qualifierare the spring annotation while@Resourceis the standard java annotation (from JSR-250) . Besides ,@Resourceonly supports for fields and setter injection while@Autowiredsupports fields , setter ,constructors and multi-argument methods injection.It is suggested to use
@Resourcefor fields and setter injection. Stick with@Qualifierand@Autowiredfor constructor or a multi-argument method injection.See this: