您好,登錄后才能下訂單哦!
普通接口與實現類
public interface DemoService
{
String sayHello(String msg);
}
public class DemoServiceImpl implements DemoService
{
@Override
public String sayHello(String msg)
{
return "hello " + msg;
}
}
dubbo服務提供者配置
<?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">
<!-- 提供方應用信息,用于計算依賴關系 -->
<dubbo:application name="hello-world-app"/>
<!-- 使用multicast廣播注冊中心暴露服務地址 -->
<!--<dubbo:registry address="multicast://224.5.6.7:1234"/>-->
<!-- 用dubbo協議在20880端口暴露服務 -->
<dubbo:protocol name="rmi" port="9123" codec="spring"/>
<!-- 聲明需要暴露的服務接口 -->
<dubbo:service interface="com.dubbo.rmi.DemoService" ref="demoService" registry="N/A" path="hello"/>
<!-- 和本地bean一樣實現服務 -->
<bean id="demoService" class="com.dubbo.rmi.DemoServiceImpl"/>
</beans>
dubbo服務消費者配置
<?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">
<!-- 提供方應用信息,用于計算依賴關系 -->
<dubbo:application name="hello-world-app-consumer"/>
<!-- 使用multicast廣播注冊中心暴露服務地址 -->
<!-- <dubbo:registry address="multicast://224.5.6.7:1234"/> -->
<!-- 聲明需要暴露的服務接口 -->
<dubbo:reference interface="com.dubbo.rmi.DemoService" id="demoService" url="rmi://localhost:9123/hello" registry="N/A"/>
</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">
<!--RMI的服務實現類-->
<bean id="demoService" class="com.dubbo.rmi.DemoServiceImpl" />
<bean id="serviceExporter" class="org.springframework.remoting.rmi.RmiServiceExporter">
<!--配置RMI的服務實現類-->
<property name="service" ref="demoService" />
<!--配置RMI的服務接口-->
<property name="serviceInterface" value="com.dubbo.rmi.DemoService"/>
<!--暴露的對外服務名-->
<property name="serviceName" value="hello" />
<!--服務本地注冊端口-->
<property name="registryPort" value="9123" />
<!--服務對外暴露端口-->
<property name="servicePort" value="9123" />
<!--注冊服務-->
<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相互調用注意點
端口須匹配
<dubbo:service path="hello"> 與 springRMI配置<property name="serviceName" value="hello" /> 要一致, dubbo默認為接口全路徑
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。