首先新建兩個web項目,並添加相關jar包。<?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
">
<!-- 具體的實現bean -->
<bean id="helloWordlService" class="com.sinontech.project.douInterface.HelloWordlService" />
<!-- 提供方應用信息,用於計算依賴關係 -->
<dubbo:application name="xixi_provider" />
<!-- 使用multicast廣播註冊中心暴露服務地址 -->
<dubbo:registry address="multicast://224.5.6.7:1234" />
<!-- 使用zookeeper註冊中心暴露服務地址
<dubbo:registry address="zookeeper://127.0.0.1:2181" /> -->
<!-- 用dubbo協議在20880端口暴露服務 -->
<dubbo:protocol name="dubbo" port="20880" />
<!-- 聲明須要暴露的服務接口 -->
<dubbo:service interface="com.sinontech.project.douInterface.HelloWordl" ref="helloWordlService" />
</beans> 上面是服務提供項目的dubbo配置。web
<?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="hehe_consumer" />
<!-- 使用zookeeper註冊中心暴露服務地址 <dubbo:registry address="zookeeper://127.0.0.1:2181" /> -->
<dubbo:registry address="multicast://224.5.6.7:1234" />
<!-- 生成遠程服務代理,能夠像使用本地bean同樣使用demoService -->
<dubbo:reference id="helloWordlService"
interface="com.sinontech.project.douInterface.HelloWordl" />
</beans> spring
這是消費項目的dubbo配置。app
@RequestMapping(value="dubboTest",method = RequestMethod.GET)
public void dubboTest(){
HelloWordl helloWordlService=(HelloWordl)ApplicationUtil.getBean("helloWordlService");
helloWordlService.say();
}ide
總結spa
這也是網上的demo修改的,感受使用dubbo仍是比較簡單的。代理