1, <context:annotation-config/> and <context:component-scan base-package= "xx.xx"/>
In a host-based configuration spring configuration file, you may see a configuration like <context:annotation-config/> that is registered with the spring container autowiredannotationbeanpostprocessor,commonannotationbeanpostprocessor, Persistenceannotationbeanpostprocessor and requiredannotationbeanpostprocessor the 4 beanpostprocessor.
Registering these 4 beanpostprocessor functions is for your system to be able to identify the corresponding annotations.
For example:
If you want to use @Autowired annotations, you must declare the autowiredannotationbeanpostprocessor Bean in the Spring container beforehand . The traditional declaration method is as follows
<bean class= "Org.springframework.beans.factory.annotation. Autowiredannotationbeanpostprocessor "/>
If you want to use @ Resource,@ postconstruct,@ Predestroy and other annotations, you must declare commonannotationbeanpostprocessor
If you want to use @PersistenceContext annotations, you must declare the Persistenceannotationbeanpostprocessor Bean.
If you want to use @Required annotations, you must declare the Requiredannotationbeanpostprocessor Bean. Similarly, the traditional way of declaring is as follows:
<bean class= "Org.springframework.beans.factory.annotation.RequiredAnnotationBeanPostProcessor"/>
Generally speaking, these annotations we are more commonly used, especially antowired annotations, in the automatic injection is often used, so if you always need to follow the traditional way a configuration is a bit cumbersome and unnecessary,
So Spring provides us with a simplified configuration of <context:annotation-config/> to help you complete the declaration automatically.
However, we usually use annotations to configure the scan package path option <context:component-scan base-package= "xx.xx"/>
This configuration item also includes the ability to automatically inject the above processor, so when <context:component-scan/> is used , the <context can be : Annotation-config/> removed.
For example:
<!--<context:annotation-config/> can be removed.
<!--automatically scan assembly--with annotations
<context:component-scan base-package= "Com.aaa.action"/>
<context:component-scan base-package= "Com.aaa.service"/>
<context:component-scan base-package= "Com.aaa.dao"/>
Spring Annotation Mode configuration instructions