Can't exclude logback-classic dependency from dropwizard project

时光总嘲笑我的痴心妄想 提交于 2019-12-11 09:45:52

问题


I am working a number of projects that are using Dropwizard 0.8.2 with sfl4j-api 1.7.12 for logging. Our chosen implementation for slf4j is slf4j-log4j12, but we are having a problem with multiple implementations present in the project.

When trying to run it, it complains that multiple SLF4J bindings are present. One is ours, the other is logback-classic which is coming from the dropwizard-jackson dependency.

The problem is when we try to exclude logback-classic from the dependencies we get the following error when trying to start the server:

Exception in thread "main" java.lang.NoClassDefFoundError: ch/qos/logback/classic/filter/ThresholdFilter
    at io.dropwizard.Application.<clinit>(Application.java:20)
Caused by: java.lang.ClassNotFoundException: ch.qos.logback.classic.filter.ThresholdFilter
    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)
    ... 1 more

Is there any way that people know of to use log4j with Dropwizard?


回答1:


I don't think you can remove logback from the runtime classpath and make dropwizard use some other logging implementation (without modifying dropwizard's code). As we can see, io.dropwizard.Application's static initializer calls io.dropwizard.logging.LoggingFactory.bootstrap(), and LoggingFactory directly uses classes from logback, so LoggingFactory class just won't initialize without logback.



来源:https://stackoverflow.com/questions/32891708/cant-exclude-logback-classic-dependency-from-dropwizard-project

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!