将 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):
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
最佳答案
如果你不想使用 logback 作为记录器,那么你只需要将它从所有配置中排除,如下所示:
configurations.all {
exclude group: "ch.qos.logback"
}
dependencies {
// ... all your dependencies here.
}
在您的 github 项目示例中:您已在
buildscript
中声明了排除规则 block ,这是错误的。您需要在此 block 之外配置这些排除项(=> 与 repositories
或 dependencies
block 处于同一级别)备注 您的日志记录问题的根本原因是
spring-boot
和 active-mq-all
依赖项在其传递依赖项中提供 Slf4j 绑定(bind)实现,因此您需要排除 logback
(参见上面的解决方案)或来自 active-mq
的实现(这似乎更复杂:见 https://stackoverflow.com/a/11786595/6899896 )
关于spring-boot - Spring Boot 2.0.5 - Activemq 5.14.0 与带有 gradle 的设置记录器有关的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52656734/