spring 支持annotation bean,需要添加配置:
<context:component-scan base-package="com.x.y.*" />
等价于 <context:component-scan base-package="com.x.y.*" annotation-config="true"/>,不需要<context:annotation-config />配置项。
component-scan解析过程中,会register-Annotation-Processors, 完成annotation-config 的工作。
<context:annotation-config />
作用:注册bean annotation 解析器(BeanPostProcessors)
常用的注解和对应的解析器:
ConfigurationClassPostProcessor
@Configuration @Component @Bean
AutowiredAnnotationBeanPostProcessor
@Autowired @Value @Inject
RequiredAnnotationBeanPostProcessor
@Required
CommonAnnotationBeanPostProcessor
@PostConstruct @PreDestroy @Resource