BlazeDS與Spring結合的工廠類分析

2021-08-22 20:01:15 字數 1643 閱讀 7808

《blazeds開發指南》的第十六章介紹了blazeds的一種擴充套件方法——通過工廠類,可以自定義出各種控制項以滿足實際應用中的需求,在這章中給出了乙個與spring結合的方法,下面先給出具體**,然後再詳細分析一下,個人拙見,如有錯誤,希望指出,具體**工程見附件,其中包括乙個spring-flex.jar的包,在實際應用中可以直接拷貝到類路徑中。

public class springfactory implements flexfactory

//該方法在乙個destination被例項化時呼叫。

@override

public factoryinstance createfactoryinstance(string id, configmap properties)

//返回乙個指定source和property的工廠例項,該方法會在每次服務請求時自動呼叫。

@override

public object lookup(factoryinstance inst)

class springfactoryinstance extends factoryinstance

//由servlet容器中獲取上下文內容(context),然後根據配置源獲取spring中建立的bean。

@override

public object lookup()

catch(nosuchbeandefinitionexception nexc) //沒有找到指定的bean。

catch(bean***ception bexc) //建立bean出錯。

}@override

public string tostring()

}}

(1)在實際應用中,我們首先在blazeds的配置檔案services-config.xml中定義乙個工廠,**如下:

(2)然後,在該web應用的配置檔案web.xml中新增如下定義,啟用spring的支援:

contextconfiglocation

org.springframework.web.context.contextloaderlistener

注意上面的bean名稱somespringbean,會在下面用到。

(4)最後,在blazeds的配置檔案remoting-config.xml中定義我們的destination,其中通過factory和source把blazeds和spring相結合起來了,如下:

spring

somespringbean

通過以上步驟,已經把spring和blazeds結合起來了,當我們在flex客戶端呼叫服務端的somedestination時,因為該destination中有乙個factory——spring,所以轉交給org.springflex.factories.springfactory處理,而在springfactoryinstance類的lookup方法中,先獲得該servlet的上下文環境,再獲取該destination的source,而該source正是在spring中定義的bean名稱,所以,最後通過獲取該bean來呼叫org.springflex.somebean,達到了最終呼叫的目的。

附件:springfactory.rar(我是在jdk-1.6.u7下編譯的)

BlazeDS 與Spring整合指南之一

springsource與adobe合作發布了spring與blazeds整合的專案spring blazeds integration,通過spring blazeds integration可以把spring的bean暴露為blazeds的flex remoting service,這樣flex...

sockaddr與sockaddr in結構體簡介

struct sockaddr sa family是位址家族,一般都是 af 的形式。好像通常大多用的是都是af inet。sa data是14位元組協議位址。此資料結構用做bind connect recvfrom sendto等函式的引數,指明位址資訊。但一般程式設計中並不直接針對此資料結構操作...

sockaddr與sockaddr in結構體簡介

struct sockaddr sa family是位址家族,一般都是 af 的形式。好像通常大多用的是都是af inet。sa data是14位元組協議位址。此資料結構用做bind connect recvfrom sendto等函式的引數,指明位址資訊。但一般程式設計中並不直接針對此資料結構操作...