Spring and @Resource annotations

Source: Internet
Author: User

@autowired annotations are supported in Spring to enable bean injection. Also, Spring supports @resource annotations, which, like @autowired, implement bean injection. The note exists in the Javax.annotation.Resource package.

Here's how to use it:

  

1 Import Javax.annotation.Resource; 2  Public class a{34  @Resource5   private  b b;      6    7 }

Where @resource has two parameters in the spring configuration to find the exact bean, respectively, "name" and "type", the Name property is the name of the bean, that is, the set ID;

Type is a class type, which is the type of the bean. Throws an exception if it is not found. The default setting, name, is based on the Bean's ID property. Set format

@Resource (name= "B", type= "B").

Spring and @Resource annotations

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.