Bean的生命周期(3)
阿新 • • 發佈:2018-04-25
bean生命周期配置Bean的初始化和銷毀的方法:
配置初始化和銷毀的方法:
* init-method=”setup”
* destroy-method=”teardown”
執行銷毀的時候,必須手動關閉工廠,而且只對scope=”singleton”有效.
##### Bean的生命周期的11個步驟:
1. instantiate bean對象實例化
2. populate properties 封裝屬性
3. 如果Bean實現BeanNameAware 執行 setBeanName
4. 如果Bean實現BeanFactoryAware 或者 ApplicationContextAware 設置工廠 setBeanFactory 或者上下文對象 setApplicationContext
5. 如果存在類實現 BeanPostProcessor(後處理Bean) ,執行postProcessBeforeInitialization
6. 如果Bean實現InitializingBean 執行 afterPropertiesSet
7. 調用<bean init-method="init"> 指定初始化方法 init
8. 如果存在類實現 BeanPostProcessor(處理Bean) ,執行postProcessAfterInitialization
9. 執行業務處理
10. 如果Bean實現 DisposableBean 執行 destroy
11. 調用<bean destroy-method="customerDestroy"> 指定銷毀方法 customerDestroy
在CustomerService類的add方法之前進行權限校驗?
Bean的生命周期(3)