The project uses dubbo, zookeeper service report Can not initialize class org.I0Itec.zkclient.ZkClient

Keywords: Dubbo Java Zookeeper log4j

dubbo service is used in the project, zookeeper is used as the registry, logback is used as the log framework, and errors are reported as follows when starting the project:

Caused by: java.lang.NoClassDefFoundError: Could not initialize class org.I0Itec.zkclient.ZkClient
    at com.alibaba.dubbo.remoting.zookeeper.zkclient.ZkclientZookeeperClient.<init>(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.<init>(ZookeeperRegistry.java:71) ~[dubbo-2.5.3.jar:2.5.3]

Look at the first sentence Caused by: java.lang.NoClassDefFoundError: Can not initialize class org.I0Itec.zkclient.ZkClient
We can't find the initialization ZKClient class. We checked the resources on the Internet. We said that there is no jar package. Look at the project pom, we did introduce the jar.

        <dependency>
            <groupId>com.101tec</groupId>
            <artifactId>zkclient</artifactId>
            <version>0.3</version>
        </dependency>

Turn over the log and see a line

java.lang.NoClassDefFoundError: org/apache/log4j/Logger
    at org.I0Itec.zkclient.ZkClient.<clinit>(ZkClient.java:57) ~[zkclient-0.3.jar:0.3]
    at com.alibaba.dubbo.remoting.zookeeper.zkclient.ZkclientZookeeperClient.<init>(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]

Say there is a lack of log4j package, so dubbo uses log4j internally, and I added excluding log4j in my final pom

<exclusions>
                <exclusion>
                    <groupId>org.slf4j</groupId>
                    <artifactId>slf4j-log4j12</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>log4j</groupId>
                    <artifactId>log4j</artifactId>
                </exclusion>
            </exclusions>

Estimate this is the problem, then delete log4j exclusion, restart, success.

Posted by mr.echo on Wed, 13 Feb 2019 18:42:19 -0800