java中分散式框架dubbo的配置
阿新 • • 發佈:2019-02-13
pom.xml中配置
<!-- dubbo -->
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>dubbo</artifactId>
<version>2.5.6</version>
<!--使用自定義的spring版本避免dubbo自帶的spring產生版本衝突-->
<exclusions >
<exclusion>
<groupId>org.springframework</groupId>
<artifactId>spring</artifactId>
</exclusion>
</exclusions>
</dependency>
dubbo提供者配置applicationContext-dubbo-provider.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="zheng-cms-admin"/>
<dubbo:registry file="./zheng-cms-admin-dubbo.cache" address="zookeeper://zkserver:2181"/>
<!-- 訂閱服務 -->
<dubbo:consumer check="false"/>
<!-- 文章 -->
<dubbo:reference id="cmsArticleService" interface="com.zheng.cms.rpc.api.CmsArticleService" mock="true"/>
<!-- 類目 -->
<dubbo:reference id="cmsCategoryService" interface="com.zheng.cms.rpc.api.CmsCategoryService" mock="true"/>
<!-- 評論 -->
<dubbo:reference id="cmsCommentService" interface="com.zheng.cms.rpc.api.CmsCommentService" mock="true"/>
<!-- 標籤 -->
<dubbo:reference id="cmsTagService" interface="com.zheng.cms.rpc.api.CmsTagService" mock="true"/>
<!-- 專題 -->
<dubbo:reference id="cmsTopicService" interface="com.zheng.cms.rpc.api.CmsTopicService" mock="true"/>
<!-- 選單 -->
<dubbo:reference id="cmsMenuService" interface="com.zheng.cms.rpc.api.CmsMenuService" mock="true"/>
<!-- 單頁 -->
<dubbo:reference id="cmsPageService" interface="com.zheng.cms.rpc.api.CmsPageService" mock="true"/>
<!-- 設定 -->
<dubbo:reference id="cmsSettingService" interface="com.zheng.cms.rpc.api.CmsSettingService" mock="true"/>
<!-- 系統 -->
<dubbo:reference id="cmsSystemService" interface="com.zheng.cms.rpc.api.CmsSystemService" mock="true"/>
<!-- 介面服務 -->
<dubbo:reference id="upmsApiService" interface="com.zheng.upms.rpc.api.UpmsApiService" mock="true"/>
</beans>
dubbo消費者配置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="zheng-cms-admin"/>
<dubbo:registry file="./zheng-cms-admin-dubbo.cache" address="zookeeper://zkserver:2181"/>
<!-- 訂閱服務 -->
<dubbo:consumer check="false"/>
<!-- 文章 -->
<dubbo:reference id="cmsArticleService" interface="com.zheng.cms.rpc.api.CmsArticleService" mock="true"/>
<!-- 類目 -->
<dubbo:reference id="cmsCategoryService" interface="com.zheng.cms.rpc.api.CmsCategoryService" mock="true"/>
<!-- 評論 -->
<dubbo:reference id="cmsCommentService" interface="com.zheng.cms.rpc.api.CmsCommentService" mock="true"/>
<!-- 標籤 -->
<dubbo:reference id="cmsTagService" interface="com.zheng.cms.rpc.api.CmsTagService" mock="true"/>
<!-- 專題 -->
<dubbo:reference id="cmsTopicService" interface="com.zheng.cms.rpc.api.CmsTopicService" mock="true"/>
<!-- 選單 -->
<dubbo:reference id="cmsMenuService" interface="com.zheng.cms.rpc.api.CmsMenuService" mock="true"/>
<!-- 單頁 -->
<dubbo:reference id="cmsPageService" interface="com.zheng.cms.rpc.api.CmsPageService" mock="true"/>
<!-- 設定 -->
<dubbo:reference id="cmsSettingService" interface="com.zheng.cms.rpc.api.CmsSettingService" mock="true"/>
<!-- 系統 -->
<dubbo:reference id="cmsSystemService" interface="com.zheng.cms.rpc.api.CmsSystemService" mock="true"/>
<!-- 介面服務 -->
<dubbo:reference id="upmsApiService" interface="com.zheng.upms.rpc.api.UpmsApiService" mock="true"/>
</beans>
這裡實現了mock=”true”所以service類要寫上Mock降級方法
如:
寫一個CmsArticleCategoryService類,
要寫一個CmsArticleCategoryServiceMock類並且要implements CmsArticleCategoryService