无法从dropwizard项目中排除经典的logback依赖 [英] Can't exclude logback-classic dependency from dropwizard project

查看:189
本文介绍了无法从dropwizard项目中排除经典的logback依赖的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在处理许多使用Dropwizard 0.8.2和sfl4j-api 1.7.12进行记录的项目.我们为slf4j选择的实现是slf4j-log4j12,但是我们在项目中存在多个实现时遇到了问题.

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.

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

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.

问题是,当我们尝试从依赖项中排除经典的logback时,在尝试启动服务器时出现以下错误:

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

人们知道将Log4j与Dropwizard一起使用吗?

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

推荐答案

我认为您无法从运行时类路径中删除日志,并使dropwizard使用其他一些日志记录实现(无需修改dropwizard的代码).如我们所见,io.dropwizard.Application的静态初始化程序

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.

这篇关于无法从dropwizard项目中排除经典的logback依赖的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆