首页  

springboot @Autowired 注解处理要点     所属分类 springboot 浏览量 1191
SpringApplication#refreshContext()

BeanUtils#instantiateClass()

AbstractAutowireCapableBeanFactory doCreateBean() populateBean()

AutowiredAnnotationBeanPostProcessor#postProcessPropertyValues

public class AutowiredAnnotationBeanPostProcessor extends InstantiationAwareBeanPostProcessorAdapter
		implements MergedBeanDefinitionPostProcessor, PriorityOrdered, BeanFactoryAware
		
public interface MergedBeanDefinitionPostProcessor extends BeanPostProcessor
	
	

findAutowiringMetadata()



private final Set<Class<? extends Annotation>> autowiredAnnotationTypes = new LinkedHashSet<>();
public AutowiredAnnotationBeanPostProcessor() {
		this.autowiredAnnotationTypes.add(Autowired.class);
		this.autowiredAnnotationTypes.add(Value.class);
		try {
			this.autowiredAnnotationTypes.add((Class<? extends Annotation>)
					ClassUtils.forName("javax.inject.Inject", AutowiredAnnotationBeanPostProcessor.class.getClassLoader()));
			logger.info("JSR-330 'javax.inject.Inject' annotation found and supported for autowiring");
		}
		catch (ClassNotFoundException ex) {
			// JSR-330 API not available - simply skip.
		}
}



inject方法  
resolveDependency 获取值

反射设置

private class AutowiredFieldElement extends InjectionMetadata.InjectedElement

protected void inject(Object bean, @Nullable String beanName, @Nullable PropertyValues pvs) throws Throwable 

ReflectionUtils.makeAccessible(field);
field.set(bean, value);


resource注解  CommonAnnotationBeanPostProcessor 处理
InjectionMetadata [line: 82] [conditional] - inject(Object, String, PropertyValues)	
设置条件断点 beanName.equals("lifeBean")




spring bean 生命周期实例 BeanPostProcessor 和 BeanFactoryPostProcessor spring bean生命周期及扩展点 eclipse设置条件断点和异常断点 Autowired和Resource注解的区别

上一篇     下一篇
SpringBoot的指标数据

cron表达式实例

团队管理的1+4+7法则

spring autowired注解不生效的一种情况

cron表达式中 * 与 ? 的区别

SpringBoot定时任务 schedule