zookeeper使用过程的错误

一、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>
原文地址:https://www.cnblogs.com/zeussbook/p/10918147.html