一、zookeeper啟動成功,dubbo服務也注冊成功,但是服務消費者調用失敗
報錯如下:
[myid:] - INFO [SyncThread:0:ZooKeeperServer@645] - Est
ablished session 0x16ae75366b60004 with negotiated timeout 40000 for client /127
.0.0.1:5094
2019-05-24 09:43:52,695 [myid:] - INFO [ProcessThread(sid:0 cport:2181)::PrepRe
questProcessor@651] - Got user-level KeeperException when processing sessionid:0
x16ae75366b60004 type:create cxid:0x4 zxid:0x3c09 txntype:-1 reqpath:n/a Error P
ath:/dubbo/sellergoods.service.BrandService/configurators Error:KeeperErrorCode
= NodeExists for /dubbo/sellergoods.service.BrandService/configurators
1、網上找了很多解決的方法:刪除zookeeper配置的data和logs中的version2的數據。但是還是不行。
后來發現這個根本不是zookeeper的錯誤,而是代碼的問題。着重檢查兩個地方。
一、pom.xml中jar包的問題,注意dubbo(阿里巴巴官方)和dubbox(當當網,一般叫做dubbo2.8.4)需要的依賴是不一樣的。
下面是當當網的dubbox的引用。
<!-- dubbo相關 --> <dependency> <groupId>com.alibaba</groupId> <artifactId>dubbo</artifactId> <version>2.8.4</version> </dependency> <dependency> <groupId>org.apache.zookeeper</groupId> <artifactId>zookeeper</artifactId> <version>3.4.7</version> </dependency> <dependency> <groupId>com.github.sgroschupf</groupId> <artifactId>zkclient</artifactId> <version>0.1</version> </dependency>
二、檢查dubbo掃描的xml文件,寫法是否有誤。官方有參照。
provider
<?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" xmlns:context="http://www.springframework.org/schema/context" xmlns:dubbo="http://code.alibabatech.com/schema/dubbo" xmlns:mvc="http://www.springframework.org/schema/mvc" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd http://code.alibabatech.com/schema/dubbo http://code.alibabatech.com/schema/dubbo/dubbo.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd"> <dubbo:protocol name="dubbo" port="20880"></dubbo:protocol> <!--<dubbo:protocol name="http" port="20881"></dubbo:protocol>--> <dubbo:application name="smallshop_goods_service" /> <dubbo:registry address="zookeeper://127.0.0.1:2181"/> <!--掃描包名--> <dubbo:annotation package="sellergoods.service.impl" /> </beans>
consumer
<?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" xmlns:context="http://www.springframework.org/schema/context" xmlns:dubbo="http://code.alibabatech.com/schema/dubbo" xmlns:mvc="http://www.springframework.org/schema/mvc" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd http://code.alibabatech.com/schema/dubbo http://code.alibabatech.com/schema/dubbo/dubbo.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd"> <context:property-placeholder location="classpath:config/application.properties" /> <mvc:annotation-driven> <mvc:message-converters register-defaults="true"> <bean class="com.alibaba.fastjson.support.spring.FastJsonHttpMessageConverter"> <property name="supportedMediaTypes" value="application/json"/> <property name="features"> <array> <value>WriteMapNullValue</value> <value>WriteDateUseDateFormat</value> </array> </property> </bean> </mvc:message-converters> </mvc:annotation-driven> <!-- 引用dubbo 服務 --> <dubbo:application name="smallshop_manager_web" /> <dubbo:registry address="zookeeper://127.0.0.1:2181" timeout="6000"/> <!--掃描包名--> <dubbo:annotation package="smallshop.manager.controller" /> </beans>