springBean生命週期----來自spring實戰總結

來源:互聯網
上載者:User

標籤:應用程式   依賴   str   預先處理   ring   屬性   after   app   init   

1、Spring對bean進行執行個體化

2、Spring將值和bean的引用注入到bean對應的屬性中(比如說注入到被依賴的bean的方法中或屬性裡)

3、如果bean實現了BeanNameAware介面,將會將bean的Id傳入setBeanName()方法中

4、如果bean實現了BeanFactoryAware介面,將會設定bean的BeanFactory的引用傳入到setBeanFactory()方法中

5、如果bean實現了ApplicationContextAware介面,Spring將調用setApplicationContext()傳入bean的內容相關的引用

6、如果bean實現了BeanPostProcessor介面,Spring將調用bean的屬性初始化之前的預先處理方法postProcessBeforeInitialization()方法

7、如果bean實現了InitializingBean介面,Spring將調用afterPropertiesSet()方法。如果bean使用init-method聲明了初始化方法,改方法也會被調用

8、如果bean實現了BeanPostProcessor介面,Spring將調用postProcessAfterInitialization

9、此時bean已經準備就緒,可以被應用程式使用了,它將一直駐留在應用上下文中,直到該應用上下文被銷毀

10、如果bean實現了DisposableBean介面,Spring將調用他的destroy()方法,如果使用了destroy-method也會調用該方法。

springBean生命週期----來自spring實戰總結

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.