spring 上下文 spring原始碼分析之上下文

2021-10-12 16:50:01 字數 1365 閱讀 8797

public void close() throws ioexception; //釋放

void start(); //啟動元件

void stop(); //同步方法停止元件

void isrunning(); //判斷元件是否啟動

lifecycle:介面對容器生命週期進行控制。

// 重新整理beanfactory,用於執行實際的配置載入,該方法在其他的初始化工作之前被refresh()方法呼叫

protected abstract void refreshbeanfactory() throws bean***ception, illegalstateexception;

// 關閉beanfactory,用於釋放內部使用的beanfactory·

protected abstract void closebeanfactory();

// 獲取內部使用的beanfactory

public abstract configurablelistablebeanfactory getbeanfactory() throws illegalstateexception;

// 設定web應用上下文的servletcontext

void setservletcontext(@nullable servletcontext servletcontext);

// 設定web應用上下文的servletconfig

void setservletconfig(@nullable servletconfig servletconfig);

// 獲取web應用上下文的servletconfig

servletconfig getservletconfig();

// 設定web應用上下文的命名空間

void setnamespace(@nullable string namespace);

// 獲取web應用上下文的命名空間

string getnamespace();

// 以初始化引數的形式設定web應用上下文的配置檔案位置

void setconfiglocation(string configlocation);

// 設定web應用上下文的配置檔案的位置

void setconfiglocations(string... configlocations);

// 獲取web應用上下文的配置檔案位置

string getconfiglocations();

Spring共享上下文機制

對於spring應用程式上下文的引用基本有兩種形式,一種就是通過實現spring提供的aware介面來得到spring容器的應用程式上下文,第二種就是使用 i b contextsingletonbeanfactorylocator b i 來獲得spring應用程式上下文。第一種情況就不用多說了,...

Spring例項化上下文物件

從前面的例子可以看到,在 中例項化上下文物件非常簡單,如下面的例子 fooservice foo fooservice ctx.getbean fooservice 幾個常用的類 開發中,我們經常以業務功能或業務分層的方式,定義不同的xml配置檔案。如何載入多個xml配置檔案呢?可以這樣 但是這種方...

Spring通過上下文獲取bean

某處呼叫get方法,卻報空指標異常。經查,是dao物件為null。再查,是service物件為newinstance,並沒有注入dao物件。因此修改語句,從spring中獲取service物件。已有引數 classservice 最終目標 t sv 1.sv由spring上下文context獲取 t...