不能从dropwizard项目中排除logback-classic的依赖性。[英] Can't exclude logback-classic dependency from dropwizard project

本文是小编为大家收集整理的关于不能从dropwizard项目中排除logback-classic的依赖性。的处理/解决方法,可以参考本文帮助大家快速定位并解决问题,中文翻译不准确的可切换到English标签页查看源文。

问题描述

我正在从事许多项目,这些项目正在使用dropwizard 0.8.2与sfl4j-api 1.7.12进行记录.我们为SLF4J选择的实现是Slf4j-log4j12,但是我们在项目中存在多个实现时遇到了问题.

试图运行它时,它抱怨存在多个SLF4J绑定.一个是我们的,另一个是来自dropwizard-jackson依赖的木制经典.

问题是,当我们尝试启动服务器时,我们尝试从依赖项中排除logback-classic时会遇到以下错误:

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

人们知道将Log4J与DropWizard使用吗?

推荐答案

我认为您无法从运行时类路径中删除记录返还,并使DropWizard使用其他一些日志记录实现(而无需修改DropWizard的代码).如我们所见. main/java/io/dropwizard/logging/loggingfactory.java" rel =" nofollow"> LoggingFactory 直接使用logback中的类,因此LoggingFactory类不会在没有logback的情况下初始化.

.

本文地址:https://www.itbaoku.cn/post/1575093.html

问题描述

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?

推荐答案

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.