【问题标题】:Spring Boot 2.0.5 - Activemq 5.14.0 issues with setup logger with gradleSpring Boot 2.0.5 - Activemq 5.14.0 与带有 gradle 的设置记录器有关的问题
【发布时间】:2019-03-10 10:29:11
【问题描述】:

将 activemq 添加到我的 build.gradle 后,我收到以下运行时错误。

compile("org.apache.activemq:activemq-all:5.14.0")

我试图排除模块,但这似乎并没有像我预期的那样排除 logback。请告知我可以做些什么来排除 logback。另请注意,这是一个 kotlin 应用程序,但我认为这无关紧要。

compile("org.springframework.boot:spring-boot-starter-web:${springBootVersion}")
{
            exclude module: "spring-boot-starter-logging"
            exclude module: "logback-classic"
}

这是一个例外:

Exception in thread "main" java.lang.IllegalArgumentException: LoggerFactory is not a Logback LoggerContext but Logback is on the classpath. Either remove Logback or the competing implementation (class org.slf4j.impl.Log4jLoggerFactory loaded from file:/C:/Users/z037640/.gradle/caches/modules-2/files-2.1/org.apache.activemq/activemq-all/5.14.0/858a3bd95d20e7a8949006cdb50a7c362f8825ec/activemq-all-5.14.0.jar). If you are using WebLogic you will need to add 'org.slf4j' to prefer-application-packages in WEB-INF/weblogic.xml Object of class [org.slf4j.impl.Log4jLoggerFactory] must be an instance of class ch.qos.logback.classic.LoggerContext

【问题讨论】:

标签: spring-boot gradle logback-classic


【解决方案1】:

如果你不想使用 logback 作为记录器,那么你只需要将它从所有配置中排除,如下:

configurations.all {
    exclude group: "ch.qos.logback"
}

dependencies {
   // ... all your dependencies here.
}

在您的 github 项目示例中:您在 buildscript 块中声明了排除规则,这是错误的。您需要在此块之外配置这些排除项(=> 与 repositoriesdependencies 块处于同一级别)

注意您的日志记录问题的根本原因是 spring-bootactive-mq-all 依赖项都在其传递依赖项中提供了 Slf4j 绑定实现,因此您需要排除 logback(参见解决方案以上)或来自active-mq 的实现(这似乎更复杂:参见https://stackoverflow.com/a/11786595/6899896

【讨论】:

    猜你喜欢
    • 2020-07-30
    • 2019-01-13
    • 2023-01-26
    • 1970-01-01
    • 2021-03-15
    • 1970-01-01
    • 2016-03-10
    • 2021-04-16
    • 2018-12-19
    相关资源
    最近更新 更多