Spring物件生命週期

2021-10-03 03:20:32 字數 531 閱讀 5687

1、靜態方法

2、非靜態方法

3、setter方法(有這個方法時呼叫)

4、初始化init-method

5、destory方法銷毀

即:1.bean的建立

由beanfactory讀取bean定義檔案,並生成各個例項

如果是預設的單例模式,那麼在載入spring的配置檔案的時候,會將bean例項化,放進spring的ioc容器中。

2、設定屬性(屬性注入) 

注入屬性值,對應的屬性需要有set方法

值載入spring配置檔案時,會例項化user物件,在呼叫無參構造方法例項化物件後,緊接著呼叫了setusername方法,為username屬性注入值,可以獲取正在被例項化的bean的id的值配置檔案中有幾個user型別的bean,就會列印幾個id值。

3、bean定義檔案中定義init-method初始化:

4、disposablebean的destroy(): bean銷毀。在容器關閉時,如果bean類實現disposablebean介面,則執行destroy()。

Spring物件生命週期

userinfo class com.jd.vo.userinfo lazy init true scope singleton init method init destroy method destroy name value tom property bean 生命週期主要分為四個階段 例項化...

Spring物件生命週期

bean生命週期 通過構造方法或工廠方法建立bean物件 為bean屬性賦值 呼叫 bean 的初始化方法,即init method指定方法 bean例項化完畢,可以使用 容器關閉,呼叫 bean 的銷毀方法,即destroy method指定方法。1.init method 在設定bean的屬性後...

spring物件生命週期

例子 spring config.xml 1.0 encoding utf 8 xmlns xsi xsi schemalocation spring beans.xsd 設定懶載入,單例模式,只有在使用這個物件的時候才會去建立 f1 class com.wance.entity.plane sco...