spring application 之 AnnotationConfigApplicationContext

创建

ApplicationContext applicationContext = new AnnotationConfigApplicationContext(NacosConfiguration.class);

AnnotationConfigApplicationContext 构造方法

public AnnotationConfigApplicationContext() {
		this.reader = new AnnotatedBeanDefinitionReader(this);
		this.scanner = new ClassPathBeanDefinitionScanner(this);
	}

AnnotatedBean读取

Contional 条件注解解析类,是否需要忽略当前类

this.conditionEvaluator = new ConditionEvaluator(registry, environment, null);

默认注解配置处理器

AnnotationConfigUtils.registerAnnotationConfigProcessors(this.registry);
排序注解器
beanFactory.setDependencyComparator(AnnotationAwareOrderComparator.INSTANCE);
依赖解决处理器

处理@Lazy @Value @Qualifier @Required @Autowired

beanFactory.setAutowireCandidateResolver(new ContextAnnotationAutowireCandidateResolver());
BeanDefinitionRegistryPostProcessor

处理CompoentScan等,

if (!registry.containsBeanDefinition(CONFIGURATION_ANNOTATION_PROCESSOR_BEAN_NAME)) {
			RootBeanDefinition def = new RootBeanDefinition(ConfigurationClassPostProcessor.class);
			def.setSource(source);
			beanDefs.add(registerPostProcessor(registry, def, CONFIGURATION_ANNOTATION_PROCESSOR_BEAN_NAME));
		}
AutowiredAnnotationBeanPostProcessor

解决@Autowired,@Value,对于注解类,需要一个后置处理器获取所有含有@Autowired,@Value的属性。对于XML不需要。

RequiredAnnotationBeanPostProcessor

校验@Required修改的属性有值没有

CommonAnnotationBeanPostProcessor

解决@Resource 注解,类似于@Autowired,@PreDestroy @PostConstruct

EventListenerMethodProcessor

单例Bean初始完之后执行。解决@EventListener,该注解用于方法之上,会生成一个ApplicationListern注册到ApplicationContext中。

DefaultEventListenerFactory

注入一个EventListenerFactory,与上面的@EventListener配合使用。

ClassPathBeanDefinitionScanner扫描器

转载于:https://my.oschina.net/u/3217171/blog/3059874

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值