AutowiredAnnotationBeanPostProcessor是实现@Autowired的关键,它本身是在何时添加到sping容器中的?
xml方式
在使用xml方式开发的过程中,我们程序入口一般是ClassPathXmlApplicationContext
@Test
public void test() throws Exception{
ClassPathXmlApplicationContext applicationContext = new ClassPathXmlApplicationContext("spring-test.xml");
Student student = (Student)applicationContext.getBean("student");
System.out.println(student.getUsername()+" "+student.getPassword());
}
创建ClassPathXmlApplicationContext时,会调用this构造函数

在构造函数中调用父类构造函数,完成一些属性的加载,以及配置文件路径的解析工作,然后进入正题——refresh()

</

这篇博客探讨了在XML和注解方式下,Spring框架中AutowiredAnnotationBeanPostProcessor的注册时机。在XML方式中,它在ClassPathXmlApplicationContext的refresh()方法中,通过loadBeanDefinitions和registerBeanDefinitions过程完成注册。而在注解方式下,通过AnnotationConfigApplicationContext,注册发生在AnnotatedBeanDefinitionReader的构造过程中。
最低0.47元/天 解锁文章
1506

被折叠的 条评论
为什么被折叠?



