近期,本公司有個舊的spring系統需要調用新系統的dubbo服務,在網上找了好久,也查閱了不少資料,總算能夠順利調通了。在此我總結一下:
首先,得引用dubbo的一些依賴jar包,不管是maven項目還是非maven項目都需要(demo我後期在上傳,jar包在本人資源裏有上傳)。
引入完jar包後,還得引入所需調用dubbo服務的api包。
然後,因爲是作爲調用方,所以得加入一個dubbo的消費者配置文件(在spring配置文件的同級目錄下添加即可),我項目中的配置文件applicationContext-dubbo-consumer.xml(僅供參考):
<?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="ibs_consumer" />
<!-- 使用zookeeper註冊中心暴露服務地址 -->
<dubbo:registry address="${dubbo.registry.address}"/>
<dubbo:reference id="wallbcOpenapi102TransRpcService"
interface="com.gnete.wallbc.rpc.WallbcOpenapi102TransRpcService"
version="1.0.1" check="false" timeout="10000"/>
<dubbo:reference id="wallbcOpenapi102QueryRpcService"
interface="com.gnete.wallbc.rpc.WallbcOpenapi102QueryRpcService"
version="1.0.1" check="false" timeout="10000"/>
</beans>
最後,再把這些要用到的Service注入進你本地項目的Service類裏面即可,注入的方法和普通的Service一樣。
好了,至此就是配置完成了。至於怎麼使用的話,就是取到dubbo服務的Service處理類,就可隨便操作了。