java - log4j、log4j2冲突问题
迷茫
迷茫 2017-04-18 10:38:47
0
3
788
迷茫
迷茫

业精于勤,荒于嬉;行成于思,毁于随。

全部回覆(3)
洪涛
  1. zookeeper-3.4.0 之后的版本已经使用了slf4j的日志接口,可以直接将log4j的相關依賴排除掉。

  2. 如果zookeeper3.4.0之前的版本需要对zookeeper進行升級,重複第1步操作

zookeeper-3.4.0


kafka_2.9.1-0.8.2.2

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

剛剛看了一下kafka中使用的zkclient版本比较的低,在高版本中zkclient也已经切换至slf4j的接口了,可以将zkclient升級一下。

Ty80
<dependency>
      <groupId>org.apache.kafka</groupId>
      <artifactId>kafka_2.9.1</artifactId>
      <version>0.8.2.2</version>
      <exclusions>
          <exclusion>
               <artifactId>log4j</artifactId>
               <groupId>log4j</groupId>
          </exclusion>
     </exclusions>
</dependency>

做了排除之後報錯:

java.lang.NoClassDefFoundError: org/apache/log4j/Logger

    at org.I0Itec.zkclient.ZkClient.<clinit>(ZkClient.java:57)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:606)
    at org.junit.runners.model.FrameworkMethod.runReflectiveCall(FrameworkMethod.java:50)
    at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
    at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
    at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
    at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
    at org.junit.runners.ParentRunner.run(ParentRunner.java:290)
    at org.junit.runners.ParentRunner.schedule(ParentRunner.java:71)
    at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
    at org.junit.runners.ParentRunner.accessrrreee0(ParentRunner.java:58)
    at org.junit.runners.ParentRunner.evaluate(ParentRunner.java:268)
    at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
    at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
    at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:119)
    at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:42)
    at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:234)
    at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:74)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:606)
    at com.intellij.rt.execution.application.AppMain.main(AppMain.java:144)
Caused by: java.lang.ClassNotFoundException: org.apache.log4j.Logger
    at java.net.URLClassLoader.run(URLClassLoader.java:366)
    at java.net.URLClassLoader.run(URLClassLoader.java:355)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
    ... 30 more

zookeeper 版本3.4.6

巴扎黑

在排除 log4j 後,加上這個 log4j-1.2-api

熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板