spring源码系列

5.Spring源码系列-激活注解

2020-09-14  本文已影响0人  小明oh

介绍

在xml文件中配置<context:annotation-config/>会激活下面的注解:

  • 优先级注解:@Order、@Priority
  • 配置注解器:@Configuration
  • 编织注解器:@Autowired、@Inject、@Value、@Resource
  • @Required、@LookUp、@Lazy
  • 过程处理器:@PreDestroy、@PostConstruct
  • 数据持久:@PersistenceContext、 @PersistenceUnit
  • 事件监听:@EventListener

调用过程

  1. AnnotationConfigBeanDefinitionParser.parse
//激活注解
Set<BeanDefinitionHolder> processorDefinitions =                AnnotationConfigUtils.registerAnnotationConfigProcessors(parserContext.getRegistry(), source);

  1. 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);
上一篇下一篇

猜你喜欢

热点阅读