@ 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