我了解到IOC容器负责bean的创建、依赖项的注入和生命周期管理。那么,IOC容器的内部实现是什么?在创建bean和销毁bean之前,会发生什么过程?
发布于 2018-02-08 16:09:59
BeanNameAware
,则Spring将bean的ID传递给setBeanName()
方法。BeanFactoryAware
,则Spring调用setBeanFactory()
方法,传入bean工厂本身。ApplicationContextAware
,则Spring调用setApplicationContext()
方法,传递对封闭应用程序上下文的引用。BeanPostProcessor
接口,那么Spring将调用它的postProcessBeforeInitialization()
方法。InitializingBean
接口,那么Spring将调用它的afterPropertiesSet()
方法。类似地,如果使用init-method
声明bean,则调用指定的初始化方法。BeanPostProcessor
,那么Spring将调用它的postProcessAfterInitialization()
方法。DisposableBean
接口,那么Spring将调用它的destroy()
方法。同样,如果使用destroy-method
声明bean,则调用指定的方法。
https://stackoverflow.com/questions/48670503
复制相似问题