出现异常日志:

Caused by: java.lang.NoClassDefFoundError: org/apache/log4j/Logger
    at org.I0Itec.zkclient.ZkClient.<clinit>(ZkClient.java:57)
    at com.alibaba.dubbo.remoting.zookeeper.zkclient.ZkclientZookeeperClient.<init>(ZkclientZookeeperClient.java:25)
    at com.alibaba.dubbo.remoting.zookeeper.zkclient.ZkclientZookeeperTransporter.connect(ZkclientZookeeperTransporter.java:10)
    at com.alibaba.dubbo.remoting.zookeeper.ZookeeperTransporter$Adpative.connect(ZookeeperTransporter$Adpative.java)
    at com.alibaba.dubbo.registry.zookeeper.ZookeeperRegistry.<init>(ZookeeperRegistry.java:71)
    at com.alibaba.dubbo.registry.zookeeper.ZookeeperRegistryFactory.createRegistry(ZookeeperRegistryFactory.java:37)
    at com.alibaba.dubbo.registry.support.AbstractRegistryFactory.getRegistry(AbstractRegistryFactory.java:94)
    at com.alibaba.dubbo.registry.RegistryFactory$Adpative.getRegistry(RegistryFactory$Adpative.java)
    at com.alibaba.dubbo.registry.integration.RegistryProtocol.refer(RegistryProtocol.java:240)
    at com.alibaba.dubbo.rpc.protocol.ProtocolFilterWrapper.refer(ProtocolFilterWrapper.java:60)
    at com.alibaba.dubbo.rpc.protocol.ProtocolListenerWrapper.refer(ProtocolListenerWrapper.java:63)
    at com.alibaba.dubbo.rpc.Protocol$Adpative.refer(Protocol$Adpative.java)
    at com.alibaba.dubbo.config.ReferenceConfig.createProxy(ReferenceConfig.java:397)
    at com.alibaba.dubbo.config.ReferenceConfig.init(ReferenceConfig.java:300)
    at com.alibaba.dubbo.config.ReferenceConfig.get(ReferenceConfig.java:138)
    at com.alibaba.dubbo.config.spring.ReferenceBean.getObject(ReferenceBean.java:65)
    at org.springframework.beans.factory.support.FactoryBeanRegistrySupport.doGetObjectFromFactoryBean(FactoryBeanRegistrySupport.java:168)
    ... 25 more
Caused by: java.lang.ClassNotFoundException: org.apache.log4j.Logger
    at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
    ... 42 more
 

 

解决方案:

pom文件添加log4j依赖即可,如下所示:

<dependency>
   <groupId>log4j</groupId>
   <artifactId>log4j</artifactId>
   <version>1.2.7</version>
</dependency>
Logo

权威|前沿|技术|干货|国内首个API全生命周期开发者社区

更多推荐