歡迎您光臨本站 註冊首頁

Spring中bean的實例化順序

←手機掃碼閱讀     火星人 @ 2014-03-09 , reply:0

  載入順序:

  先構造函數——>然後是b的set方法注入——>InitializingBean的afterPropertiesSet方法——>init-method方法

  以下內容是從書中摘錄來的,但是我發現即使摘錄一遍,對其內容的理解也會更加深入!

  Spring裝配Bean的過程

  1. 實例化;

  2. 設置屬性值;

  3. 如果實現了BeanNameAware介面,調用setBeanName設置Bean的ID或者Name;

  4. 如果實現BeanFactoryAware介面,調用setBeanFactory 設置BeanFactory;

  5. 如果實現ApplicationContextAware,調用setApplicationContext設置ApplicationContext

  6. 調用BeanPostProcessor的預先初始化方法;

  7. 調用InitializingBean的afterPropertiesSet()方法;

  8. 調用定製init-method方法;

  9. 調用BeanPostProcessor的后初始化方法;

  Spring容器關閉過程

  1. 調用DisposableBean的destroy();

  2. 調用定製的destroy-method方法;


[火星人 ] Spring中bean的實例化順序已經有929次圍觀

http://coctec.com/docs/java/show-post-60207.html