XML中配置context:component-scan时,spring会自动的扫描这个包下被这些注解标识的类@Component,@Service,@Controller,@Repository,同时自动注册为bean
同时context:component-scan包含了context:annotation-config的属性开关功能
具体的属性注册四个BeanPostProcessor:
AutowiredAnnotationBeanPostProcessor、CommonAnnotationBeanPostProcessor、
PersistenceAnnotationBeanPostProcessor 、RequiredAnnotationBeanPostProcessor。
AutowiredAnnotationBeanPostProcessor的注册对应使用@Autowired注解,
CommonAnnotationBeanPostProcessor注册对应使用@ Resource 、@ PostConstruct、@ PreDestroy注解,
PersistenceAnnotationBeanPostProcessor 注册对应使用@PersistenceContext注解,
RequiredAnnotationBeanPostProcessor注册对应使用@Required注解。
由于我们一般使用context:component-scan(包含自动注入上方的四个BeanPostProcessor)功能的注解包的扫描,context:annotation-config的存在基本可以忽略了
context:component-scan的子标签包含了
<context:exclude-filter type="" expression=""/> <context:include-filter type="" expression=""/>
context:exclude-filter:告知哪些类或者接口不需要被扫描
context:include-filter:告知哪些类或者接口需要被扫描,并注册成bean类
想到再补充吧