spring中bean的生命週期歷程

spring中bean的生命週期一般如下:
(1)bean實例化,查找到bean的類相關信息並通過反射實例化
(2)bean的屬性設置。設置bean的相關屬性
(3) 如果實現了BeanNameAware,調用setBeanName方法
(4)如果實現了BeanClassLoaderAware,調用setBeanClassloader方法
(5)如果實現了BeanFactoryAware,調用setBeanFactory
(6)如果實現了EnviromentAware,調用setEnviroment
(7)如果實現了EmbeddedValueResolverAware,調用setEmbeddedValueResolver方法
(8)如果實現ResouceLoaderAware,調用setResouceLoader方法
(9)如果實現了ApplicationEventPublisherAwaret,調用setApplicationEventPublisher方法
(10)如果實現了MessageSourceAware,調用setMessageSource方法
(11)如果實現了ApplicationContextAwate,調用setApplicationContext方法


如果是WebApplicaiton
(12)如果實現ServletContextAware,調用setServletContext方法


如果不是WebApplicaiton開始後置處理
(12)如果實現BeanPostProcessor,調用postProcessBeforeInitialization方法
(13)如果實現InitializingBean,調用afterPropertiesSet方法
(14)調用用戶自定義的init-method
(15)如果實現BeanPostProcessor,調用postProcessAfterInitialization方法
(16)如果實現DisposableBean,當容器關閉的時候,調用destroy方法
(17)當容器關閉,調用自定義的destroy-method

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章