项目使用dubbo 、zookeeper服务报 Could not initialize class org.I0Itec.zkclient.ZkClient

项目中使用了dubbo 服务,用zookeeper 做注册中心,用的logback 作为日志框架,在启动项目时候报错如下:

Caused by: java.lang.NoClassDefFoundError: Could not initialize class org.I0Itec.zkclient.ZkClient
    at com.alibaba.dubbo.remoting.zookeeper.zkclient.ZkclientZookeeperClient.(ZkclientZookeeperClient.java:25) ~[dubbo-2.5.3.jar:2.5.3]
    at com.alibaba.dubbo.remoting.zookeeper.zkclient.ZkclientZookeeperTransporter.connect(ZkclientZookeeperTransporter.java:10) ~[dubbo-2.5.3.jar:2.5.3]
    at com.alibaba.dubbo.remoting.zookeeper.ZookeeperTransporter$Adpative.connect(ZookeeperTransporter$Adpative.java) ~[na:2.5.3]
    at com.alibaba.dubbo.registry.zookeeper.ZookeeperRegistry.(ZookeeperRegistry.java:71) ~[dubbo-2.5.3.jar:2.5.3]

看第一句 Caused by: java.lang.NoClassDefFoundError: Could not initialize class org.I0Itec.zkclient.ZkClient
这句说是不能找到初始化ZKClient 类,查了网上资源,说是缺少 jar包,看项目pom, 确实引入了该jar

        <dependency>
            <groupId>com.101tecgroupId>
            <artifactId>zkclientartifactId>
            <version>0.3version>
        dependency>

再网上翻启动日志, 看到一行

java.lang.NoClassDefFoundError: org/apache/log4j/Logger
    at org.I0Itec.zkclient.ZkClient.(ZkClient.java:57) ~[zkclient-0.3.jar:0.3]
    at com.alibaba.dubbo.remoting.zookeeper.zkclient.ZkclientZookeeperClient.(ZkclientZookeeperClient.java:25) ~[dubbo-2.5.3.jar:2.5.3]
    at com.alibaba.dubbo.remoting.zookeeper.zkclient.ZkclientZookeeperTransporter.connect(ZkclientZookeeperTransporter.java:10) ~[dubbo-2.5.3.jar:2.5.3]
    at com.alibaba.dubbo.remoting.zookeeper.ZookeeperTransporter$Adpative.connect(ZookeeperTransporter$Adpative.java) ~[na:2.5.3]

说是缺少log4j 包,这么说dubbo内部使用的log4j, 而我在我最后pom里加入了排除log4j

<exclusions>
                <exclusion>
                    <groupId>org.slf4jgroupId>
                    <artifactId>slf4j-log4j12artifactId>
                exclusion>
                <exclusion>
                    <groupId>log4jgroupId>
                    <artifactId>log4jartifactId>
                exclusion>
            exclusions>

估计就是这个问题,然后 删除 log4j 排除 ,再重启,成功。

你可能感兴趣的:(java,springmvc)