- 图文并茂,揭秘 Spring 的 Bean 的加载过程 - 简书
- 【追根究底】doCreateBean中为什么会对earlySingletonExposure处理两次_ACME的博客-CSDN博客
- doCreateBean中对earlySingletonExposure的
- 第一次处理是提前暴露引用,解决循环引用问题。
- 第二次处理是防止对象被改变,造成的已创建对象中持有的对象和这个对象不一致。
- doCreateBean中对earlySingletonExposure的
@Configuration 和 @Component区别
@Configuration 和 @Component区别 - 简书
@Component和@Configuration作为配置类的差别_一号搬砖手的博客-CSDN博客_configuration和component的区别
注销Bean时机
- ServletContextListener#contextDestroyed
- implements ApplicationListener
- DisposableBean#destroy
【坑】close或者shutdown方法会被自动调用
使用@Bean配置的bean,如果存在close或者shutdown方法,则在bean销毁时会自动执行该方法,如果你不想执行该方法,则添加@Bean(destroyMethod=””)来防止触发销毁方法。为什么@Bean的bean会注册DisposableBean
AbstractBeanFactory#registerDisposableBeanIfNecessary
添加DisposableBean的条件
- 实现了DisposableBean、AutoCloseable接口
- destroyMethodName不为空。
@Bean是有destroyMethod属性的
构造DisposableBean(DisposableBeanAdapter)
如果有close 或者 shutdown就将其转换为DisposableBean,并注册。
Singleton引用Prototype Bean方法
Spring中不同生命周期Bean的依赖管理 - Decouple - 博客园
SmartInitializingSingleton:所有Bean实例化后调用
RootBeanDefinition & GenericBeanDefinition
Spring会首先初始化父类的RootBeanDefinition,然后根据子类的GenericBeanDefinition覆盖父类中相应的属性,最终获得子类的RootBeanDefinition