Spring中與Bean相關的介面

2021-08-03 11:38:55 字數 1420 閱讀 5844

package chapter22;

import org.springframework.beans.bean***ception;

import org.springframework.beans.factory.beanclassloaderaware;

import org.springframework.beans.factory.beanfactory;

import org.springframework.beans.factory.beanfactoryaware;

import org.springframework.beans.factory.beannameaware;

import org.springframework.beans.factory.disposablebean;

import org.springframework.beans.factory.initializingbean;

//如果被裝配的bean實現了相應的介面,就可以在bean中獲得相應的資訊。,或者進行某些操作。

public class helloserviceimpl implements helloservice,

//以下同時為介面的呼叫的順序

beannameaware,//獲得bean名,也就是標籤的id屬性值。

beanclassloaderaware,//獲得裝載過程中的classloader物件。

beanfactoryaware,//獲得beanfactory物件

initializingbean, //在bean的所有屬性設定完後,並且在呼叫完上面介面的方法後,呼叫此介面的afterpropertiesset方法

disposablebean //當銷毀bean時,呼叫此介面的destroy方法

private string greeting;

public string getgreeting()

//以下同時為方法的呼叫的順序

public void setgreeting(string greeting)

public void setbeanname(string name)

public void setbeanclassloader(classloader arg0)

public void setbeanfactory(beanfactory arg0) throws bean***ception

throws bean***ception

public void afterpropertiesset() throws exception

public  void initmethod()

public void destroy() throws exception

public  void destroymethod()

yjz

Spring中與Bean相關的介面

package chapter22 import org.springframework.beans.bean ception import org.springframework.beans.factory.beanclassloaderaware import org.springframewo...

Spring中關於Bean的生命週期相關的內容

因為我們需要依據bean註冊到容器的不同時間點進行攔截或其它一系列操作,使得程式設計師對控制反轉這一過程具有更好的控制力和介入能力。例項化物件在容器中的生命週期如下 上圖中,的四個方法,分別在bean的不同生命週期內執行,其中紅色的兩個節點分別在bean的初始化後和銷毀前執行,一共有三種實現方式 定...

Spring中Bean的配置

以下面的xml檔案舉例 第乙個bean的名稱為role,第二個bean的名稱為medicine,第三個bean的名稱為spring.chapter.mary.poison,第四個bean的名稱為spring.chapter.mary.poison 1 id和name的區別如下 id屬性具有唯一性,每...