@ Resource annotation, resource

Source: Internet
Author: User

@ Resource annotation, resource

Annotation Step 1:

A) modify the xml file. For more information, see <context: annotation-config/>

@ Autowired
A) by type by default
B) If you want to use byName, use @ Qulifier

C) Written in private field (the third injection form) (it is not recommended to destroy encapsulation)
D) if it is written on set, @ qualifier must be written on the parameter.

@ Resource (important)

A) join: j2ee/common-annotations.jar,

B) by name by default, the name cannot be found, and by type

Xml configuration:

1 <bean id = "userDAO" class = "com. bjsxt. dao. impl. UserDAOImpl"> </bean>

Note: userDAO is used by default. If it is not found, it is used by type.

1 @ Resource2 public void setUserDAO (UserDAO userDAO) {3 this. userDAO = userDAO; 4}

You can also specify the bean in the annotation: 1 @ Resource (name = "u"), which is to find the object named u.

Code link: http://pan.baidu.com/s/1c2rK9I4 password: uv8k

Jar package link: http://pan.baidu.com/s/1hs655SK password: 6h8x

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.