SCA+SPRING組件之間的引用細節

來源:互聯網
上載者:User
組件A 負責載入初始化spring及資料庫  組件B負責對外API及RMI綁定,組件B引用組件A中的DAO對象,步驟如下
1 建立 組件A與B的介面與實現
組件A
 

@Remotable//涉及到存根引用所以要加此註解

publicinterface ServiceApi {

 

EmployeesImp getName();

}
 

publicclass ServiceApiBeanimplements ServiceApi {

@Resource(name="employeesImp")

private EmployeesDaoeapi;

public EmployeesImp getName() {

System.out.println(eapi.find("admin").getPassword());

returnnull;

}

}

組件B

@Remotable

 

publicinterface Hello {

void printName();

 

}

publicclass HelloBeanimplements Hello{

 

private ServiceApiapii;

 

public ServiceApi getApii() {

returnapii;

 

}

@Reference

 

publicvoid setApii(ServiceApi apii) {

this.apii = apii;

 

}

publicvoid printName() {

//System.out.println(apii.getName());

System.out.println(apii.getName()+"");;

 

}

}

 2、配置構建描述設定檔

組件A

<?xmlversion="1.0"encoding="UTF-8"?>

<compositexmlns="http://www.osoa.org/xmlns/sca/1.0"

xmlns:sca="http://www.osoa.org/xmlns/sca/1.0"

xmlns:tuscany="http://tuscany.apache.org/xmlns/sca/1.0"

xmlns:c="http://gpwBusinessCenter"

targetNamespace="http://gpwBusinessCenter"

name="ServiceCenter">

 

<componentname="ServiceApiComponent"autowire="true">

 

<implementation.springlocation="com/sca/resource/ServiceApi.xml"/>

 

</component>

 

</composite>

組件B

<?xmlversion="1.0"encoding="UTF-8"?>

<compositexmlns="http://www.osoa.org/xmlns/sca/1.0"

xmlns:sca="http://www.osoa.org/xmlns/sca/1.0"

xmlns:tuscany="http://tuscany.apache.org/xmlns/sca/1.0"

xmlns:c="http://gpwBusinessCenter"

targetNamespace="http://gpwBusinessCenter"

name="helloCenter">

 

<sca:servicename="Hello"promote="HelloServiceComponent">

<interface.javainterface="com.sca.resource.Hello"/>

 

<tuscany:binding.rmiserviceName="HelloServiceComponentRMI"host="localhost"port="8999"></tuscany:binding.rmi>

</sca:service>

 

<componentname="HelloServiceComponent"autowire="true">

 

<implementation.springlocation="com/sca/resource/Hello.xml"/>

 

<referencename="apii"target="ServiceApiComponent"></reference>//這裡的引用與spring中的<property 引用的一樣

 

</component>

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.