<context:annotation-config> 是用于激活那些已经在spring容器里注册过的bean(无论是通过xml的方式还是通过package sanning的方式)上面的注解。
<context:component-scan>除了具有<context:annotation-config>的功能之外,<context:component-scan>还可以在指定的package下扫描以及注册javabean 。
1、<context:annotation-config/>配置作用:
他的作用是式地向 Spring 容器注册AutowiredAnnotationBeanP ostProcessor、CommonAnnotationBeanPost Processor、
PersistenceAnnotationBea nPostProcessor 以及 RequiredAnnotationBeanPo stProcessor 这 4 个BeanPostProcessor。
注册这4个
例如:
如果你想使用@Autowired注解,那么就必须事先在
<bean
如果想使用@ Resource
如果想使用@PersistenceContext注解,就必须声明PersistenceAnnotationBea
如果想使用
<bean
一般来说,这些注解我们还是比较常用,尤其是Antowired的注解,在自动注入的时候更是经常使用,所以如果总是需要按照传统的方式一条一条配置显得有些繁琐和没有必要,于是spring给我们提供<context:annotation-config/>的简化配置方式,自动帮你完成声明。
不过,呵呵,我们使用注解一般都会配置扫描包路径选项
<context:component-scan