@bean注解的解析

本文详细介绍了@bean注解的使用,包括方法的收集和具体解析步骤。首先,通过retrieveBeanMethodMetadata获取带有@bean注解的方法,并封装成BeanMethod。接着,这些方法被存储在ConfigurationClass的beanMethods集合中。在解析过程中,@bean注解的方法会被转化为BeanDefinition,并设置相应的属性。同时,@import导入的类也会被转换为BeanDefinition并注册。最后,实现了ImportBeanDefinitionRegistrar接口的类会调用registerBeanDefinitions方法进行注册。
摘要由CSDN通过智能技术生成

目录

 

一、@bean注解的方法的收集

二、@bean注解的具体解析

 

总结




 

一、@bean注解的方法的收集

@Nullable
	protected final SourceClass doProcessConfigurationClass(
			ConfigurationClass configClass, SourceClass sourceClass, Predicate<String> filter)
			throws IOException {

		//判断类上面是否有Component注解
		if (configClass.getMetadata().isAnnotated(Component.class.getName())) {
			// Recursively process any member (nested) classes first
			//递归处理有@Component注解的内部类
			processMemberClasses(configClass, sourceClass, filter);
		}

		// Process any @PropertySource annotations
		//处理PropertySources和 PropertySource注解
		for (AnnotationAttributes propertySource : AnnotationConfigUtils.attributesForRepeatable(
				sourceClass.getMetadata(), PropertySources.class,
				org.springframework.context.annotation.PropertySource.class)) {
			if (this.environment instanceof ConfigurableEnvironment) {
				//核心逻辑
				processPropertySource(propertySource);
			}
			else {
				logger.info("Ignoring @PropertySource annotation on [" + sourceClass.getMetadata().getClassName() +
						"]. Reason: Environment must implement ConfigurableEnvironment");
			}
		}

		/
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值