I. Annotations to the object dependency relationship of IOC containers
1. Annotation Benefits: Annotations can simplify the configuration of the Spring IOC container!
2. Use the annotation steps:
1) First introduce the context namespace
xmlns:context= "Http://www.springframework.org/schema/context"
2) Turn on annotation scanning
<context:component-scan base-package= "Mfq.test" ></context:component-scan>
3) using annotations
The object is added to the IOC container by means of annotations.
Create objects and manipulate object dependencies, related annotations:
@Component specifies that an object be added to the IOC container
@Repository function with @component; used in the persistence layer
@Service function with @component; use in the Business logic layer
@Controller function with @component; Use in the control layer
@Resource attribute Injection
3. For example:
Form one: Use only @component and @resource
1) Userdao.java
2) Userservice.java
3) Useraction.java
4) test class App.java
Form II: Use of proprietary annotations
1) Userdao.java
2) Userservice.java
3) Useraction.java
4. Summary:
1) using annotations, you can simplify the configuration, and you can add objects to the IOC container and Process dependencies (DI).
2) annotations can be used in conjunction with the XML configuration.