【问题标题】:Gradle Spring Boot exclude logger errorGradle Spring Boot 排除记录器错误
【发布时间】:2018-03-17 14:20:58
【问题描述】:

我收到以下错误,但我不知道为什么:

Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/commons/logging/LogFactory
at org.springframework.boot.SpringApplication.<clinit>(SpringApplication.java:179)
at ro.schedulerbot.app_starter.SchedulerBotApplication.main(SchedulerBotApplication.java:10)
Caused by: java.lang.ClassNotFoundException: org.apache.commons.logging.LogFactory

这里是我将 log4j 设置为使用的日志框架的地方:

dependencies {       
    //LOG4J
    compile group: 'org.apache.logging.log4j', name: 'log4j-api', version: '2.9.1'
    compile group: 'org.apache.logging.log4j', name: 'log4j-core', version: '2.9.1'
}

我的排除方法如下所示:

ext.excludeDefaultLogger = {
exclude group: "commons-logging", module: "commons-logging"
exclude module: "spring-boot-starter-logging"}

这就是我添加 spring 依赖项的方式:

dependencies {
//  SPRING
compile('org.springframework.boot:spring-boot-starter-web:1.5.10.RELEASE', excludeDefaultLogger)}

提前致谢!

【问题讨论】:

    标签: java spring-boot gradle


    【解决方案1】:

    Springboot 仍然需要某种日志框架来运行。如果您排除了默认选项,则需要将其替换为其他内容。 希望这会有所帮助:https://github.com/spring-projects/spring-boot/issues/8492

    【讨论】:

    • 对不起,忘了提,但我实际上使用 log4j 作为日志框架。 //LOG4J compile group: 'org.apache.logging.log4j', name: 'log4j-api', version: '2.9.1' compile group: 'org.apache.logging.log4j', name: 'log4j-core', version: '2.9.1'
    • 我认为不能排除“spring-boot-starter-logging”,因为它需要将 log4j 实现与内部接口桥接:logicbig.com/tutorials/spring-framework/spring-boot/…
    猜你喜欢
    • 2018-07-13
    • 1970-01-01
    • 2020-10-18
    • 2020-03-07
    • 1970-01-01
    • 2018-06-26
    • 1970-01-01
    • 2016-09-17
    • 2017-07-05
    相关资源
    最近更新 更多