介绍
在xml文件中配置<context:annotation-config/>会激活下面的注解:
- 优先级注解:@Order、@Priority
- 配置注解器:@Configuration
- 编织注解器:@Autowired、@Inject、@Value、@Resource
- @Required、@LookUp、@Lazy
- 过程处理器:@PreDestroy、@PostConstruct
- 数据持久:@PersistenceContext、 @PersistenceUnit
- 事件监听:@EventListener
调用过程
- AnnotationConfigBeanDefinitionParser.parse
//激活注解
Set<BeanDefinitionHolder> processorDefinitions = AnnotationConfigUtils.registerAnnotationConfigProcessors(parserContext.getRegistry(), source);
- AnnotationConfigUtils.registerAnnotationConfigProcessors
// 优先级注解
beanFactory.setDependencyComparator(AnnotationAwareOrderComparator.INSTANCE);
//
beanFactory.setAutowireCandidateResolver(new ContextAnnotationAutowireCandidateResolver());
// @Configuration
RootBeanDefinition def = new RootBeanDefinition(ConfigurationClassPostProcessor.class);
// @Autowored、@Inject、@Value
RootBeanDefinition def = new RootBeanDefinition(AutowiredAnnotationBeanPostProcessor.class);
// @Required
RootBeanDefinition def = new RootBeanDefinition(RequiredAnnotationBeanPostProcessor.class);
//@Resource、@PreDestroy、@PostConstruct
RootBeanDefinition def = new RootBeanDefinition(CommonAnnotationBeanPostProcessor.class);
//@PersistenceContext、 @PersistenceUnit
def.setBeanClass(ClassUtils.forName(PERSISTENCE_ANNOTATION_PROCESSOR_CLASS_NAME,AnnotationConfigUtils.class.getClassLoader()));
// @EventListener
RootBeanDefinition def = new RootBeanDefinition(EventListenerMethodProcessor.class);
网友评论