您好,登錄后才能下訂單哦!
普通接口與實現(xiàn)類
public interface DemoService
{
String sayHello(String msg);
}
public class DemoServiceImpl implements DemoService
{
@Override
public String sayHello(String msg)
{
return "hello " + msg;
}
}
dubbo服務(wù)提供者配置
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:dubbo="http://code.alibabatech.com/schema/dubbo"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://code.alibabatech.com/schema/dubbo
http://code.alibabatech.com/schema/dubbo/dubbo.xsd">
<!-- 提供方應(yīng)用信息,用于計算依賴關(guān)系 -->
<dubbo:application name="hello-world-app"/>
<!-- 使用multicast廣播注冊中心暴露服務(wù)地址 -->
<!--<dubbo:registry address="multicast://224.5.6.7:1234"/>-->
<!-- 用dubbo協(xié)議在20880端口暴露服務(wù) -->
<dubbo:protocol name="rmi" port="9123" codec="spring"/>
<!-- 聲明需要暴露的服務(wù)接口 -->
<dubbo:service interface="com.dubbo.rmi.DemoService" ref="demoService" registry="N/A" path="hello"/>
<!-- 和本地bean一樣實現(xiàn)服務(wù) -->
<bean id="demoService" class="com.dubbo.rmi.DemoServiceImpl"/>
</beans>
dubbo服務(wù)消費者配置
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:dubbo="http://code.alibabatech.com/schema/dubbo"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://code.alibabatech.com/schema/dubbo
http://code.alibabatech.com/schema/dubbo/dubbo.xsd">
<!-- 提供方應(yīng)用信息,用于計算依賴關(guān)系 -->
<dubbo:application name="hello-world-app-consumer"/>
<!-- 使用multicast廣播注冊中心暴露服務(wù)地址 -->
<!-- <dubbo:registry address="multicast://224.5.6.7:1234"/> -->
<!-- 聲明需要暴露的服務(wù)接口 -->
<dubbo:reference interface="com.dubbo.rmi.DemoService" id="demoService" url="rmi://localhost:9123/hello" registry="N/A"/>
</beans>
springRMI服務(wù)配置
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd">
<!--RMI的服務(wù)實現(xiàn)類-->
<bean id="demoService" class="com.dubbo.rmi.DemoServiceImpl" />
<bean id="serviceExporter" class="org.springframework.remoting.rmi.RmiServiceExporter">
<!--配置RMI的服務(wù)實現(xiàn)類-->
<property name="service" ref="demoService" />
<!--配置RMI的服務(wù)接口-->
<property name="serviceInterface" value="com.dubbo.rmi.DemoService"/>
<!--暴露的對外服務(wù)名-->
<property name="serviceName" value="hello" />
<!--服務(wù)本地注冊端口-->
<property name="registryPort" value="9123" />
<!--服務(wù)對外暴露端口-->
<property name="servicePort" value="9123" />
<!--注冊服務(wù)-->
<property name="alwaysCreateRegistry" value="true" />
</bean>
</beans>
springRMI客戶端配置
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd">
<bean id="demoService" class="org.springframework.remoting.rmi.RmiProxyFactoryBean">
<property name="serviceUrl" value="rmi://localhost:9123/hello" />
<property name="serviceInterface" value="com.dubbo.rmi.DemoService"/>
</bean>
</beans>
dubboRMI與springRMI相互調(diào)用注意點
端口須匹配
<dubbo:service path="hello"> 與 springRMI配置<property name="serviceName" value="hello" /> 要一致, dubbo默認(rèn)為接口全路徑
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報,并提供相關(guān)證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權(quán)內(nèi)容。