【问题标题】:Suddenly getting "LoggerFactory is not a Logback LoggerContext but Logback is on the classpath." and fails to run突然得到“LoggerFactory 不是 Logback LoggerContext 但 Logback 在类路径上。”并且无法运行
【发布时间】:2018-11-22 06:37:29
【问题描述】:

我到处使用 gradle 和 latest.release 来混杂,但是,最近我的 Spring boot 应用程序停止从命令行运行。当我运行gradle clean bootRun 时,我得到...

线程“main”java.lang.IllegalArgumentException 中的异常:LoggerFactory 不是 Logback LoggerContext 但 Logback 在类路径上。删除 Logback 或竞争实现(从文件加载的类 org.slf4j.impl.Log4jLoggerFactory:/.../.gradle/caches/modules-2/files-2.1/org.slf4j/slf4j-log4j12/1.7.25/ 110cefe2df103412849d72ef7a67e4e91e4266b4/slf4j-log4j12-1.7.25.jar)。如果您使用的是 WebLogic,则需要将“org.slf4j”添加到 WEB-INF/weblogic.xml 中的首选应用程序包中:org.slf4j.impl.Log4jLoggerFactory

每个this post 我试过...

configurations.all {
    exclude group: 'org.springframework.boot', module: 'spring-boot-starter-tomcat'
    exclude group: 'org.springframework.boot', module: 'spring-boot-starter-logging'
    exclude group: 'org.springframework.boot', module: 'logback-classic'
    exclude group: "org.slf4j"
}

这会消除 Logback 错误,但 spring 不会启动并且失败且没有错误。

原因:org.gradle.process.internal.ExecException: Process 'command '/Library/Java/JavaVirtualMachines/jdk-10.0.1.jdk/Contents/Home/bin/java'' 以非零退出完成值 1

我错过了什么?

【问题讨论】:

    标签: spring-boot gradle


    【解决方案1】:

    我有这个问题并通过排除 spring-boot-starter-logginglogback-classic 并在 gradle.build 中添加 spring log4j2 实现来修复它

    configurations {
        all {
            exclude group: 'org.springframework.boot', module: 'spring-boot-starter-logging'
            exclude group: 'ch.qos.logback', module: 'logback-classic'
        }
    }
    
    dependencies {
        implementation 'org.springframework.boot:spring-boot-starter-log4j2:2.2.6.RELEASE'
    

    【讨论】:

    • 我遇到了完全相同的问题并尝试了上述步骤。但我看到以下错误:错误 23048 --- [main] osbdLoggingFailureAnalysisReporter *************************** 应用程序启动失败 ** ************************* 描述:试图调用不存在的方法。尝试从以下位置进行:org.springframework.beans.factory.annotation.AnnotatedGenericBeanDefinition.(AnnotatedGenericBeanDefinition.java:58)
    • 听起来你需要检查gradle.build中的依赖版本号
    • 你能再具体一点吗?我有很多依赖项,那么我应该检查哪个版本?我是 Gradle 和 Spring 新手,所以没有什么好主意
    • “试图调用不存在的方法”是线索。有一些版本冲突。你是用 2.2.6.RELEASE for log4j2 还是其他版本?
    • 是的,我使用的是您上面提到的完全相同的版本。我的 Spring 云上下文使用 2.2.0.RELEASE,Spring 框架安全使用 1.0.0.RELEASE。龙目岛是 1.18.20
    【解决方案2】:

    Spring Boot 因为 web starter 自动配置了 Log Back 库。您应该排除 spring-boot-starter-logging 来解决问题。

    要排除 gradle 项目上的默认 LogBack 配置,

    configurations {
        all*.exclude module : 'spring-boot-starter-logging'
        all*.exclude module : 'logback-classic'
    }
    

    你也可以试试module replacement把LogBack替换成Log4j或者Log4j2

    【讨论】:

      【解决方案3】:

      需要删除..compile 'org.apache.spark:spark-sql_2.11:latest.release'

      还没弄清楚原因。

      【讨论】:

        猜你喜欢
        • 2015-08-27
        • 2017-11-09
        • 1970-01-01
        • 1970-01-01
        • 2019-05-21
        • 1970-01-01
        • 2016-04-20
        • 2015-11-30
        • 1970-01-01
        相关资源
        最近更新 更多