Bean Management (Annotation method)
1. Add a dependency package for annotations: Spring-aop.jar
2, the introduction of the configuration of spring XML file (check the official source)
3. Open the scanning of annotations
<context:component-scan base-pachage= "file directory path required for annotation scanning"/>
4, in the injected class using annotation injection: @Component ("id")
To distinguish between three-tier architectures using different annotations (the effect is consistent, just to differentiate)
@Repository:d AO layer
@Service: Service Layer
@Controller: Controller Layer
5. Using annotations: Consistent with XML
Attribute injection (annotation mode)
Simple properties
@Value ("attribute value")-------if no setter method can be added directly to the property, if there is a setter method that needs to be added to the setter method
Bean Injection
@Autowired
@Qualifier ("name")
autowired automatically injected by type, if there are two types of the same type by name injection requires another annotation to work with
@Resource (name= "name")--------provides support for JSR-250, consistent with the previous two annotations
Initialization and destruction method annotations
@PostConstruct---------Initialization
@PreDestroy--------Destruction (singleton mode Scope=singleton valid)
Scope of Action annotations
@Scope-------Default Singleton
Spring-bean (annotation mode-management and Dependency injection)