Spring IoC杂项
Contents
@Autowired 与 @Value , @Inject
这三个注解, 都是通过 AutowiredAnnotationBeanPostProcessor
类来处理的.
通过它的默认构造器可知
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.
}
}
通过构造器注入 determineCandidateConstructors
通过字段注入 AutowiredFieldElement.inject
通过方法参数注入 AutowiredMethodElement.inject