<context:annotation-config>,的作用是向Spring容器中注册
AutowiredAnnotationBeanPostProcessor
CommonAnnotationBeanPostProcessor
PersistenceAnnotationBeanPostProcessor
RequiredAnnotationBeanPostProcessor
这4个BeanPostProcessor.注册这4个BeanPostProcessor的作用,就是为了系统能够识别相应的注解。
1.使用@ Resource 、@ PostConstruct、@ PreDestroy等注解就必须声明CommonAnnotationBeanPostProcessor。
2.使用@Autowired注解,那么就必须事先在 Spring 容器中声明 AutowiredAnnotationBeanPostProcessor Bean。
3.使用@PersistenceContext注解,就必须声明PersistenceAnnotationBeanPostProcessor的Bean。
4.使用 @Required的注解,就必须声明RequiredAnnotationBeanPostProcessor的Bean。
传统方式替代<context:annotation-config>
<bean class="org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor "/>
最后,与<context:annotation-config>比较像的一个注解<context:component-scan/>
<context:component-scan/> 除了@Autowired等一些注解会识别到,还可以扫描@Component等注解,可以用注解生成bean.使用<context:component-scan/> 就可以不使用<context:annotation-config>
推荐一篇博客https://www.cnblogs.com/leiOOlei/p/3713989.html