You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Spring Boot 3.1.2 bootRun任务出现LoggerFactory异常求助

解决Logback与SLF4J LoggerFactory冲突异常

异常信息

Exception in thread "main" java.lang.IllegalArgumentException:
LoggerFactory is not a Logback LoggerContext but Logback is on classpath.
Either remove logback or the competing implementation
( class org.slf4j.helpers.NOPLoggerFactory loaded from 
file:home/user/.gradle/caches/modules-x/files-x.1/{org}/repo/snapshot/{random_number}/repo.jar.

**Using**
logback-classic version 1.4.8

问题原因

项目类路径中同时存在Logback(1.4.8版本)和SLF4J的另一个日志实现(此处为NOPLoggerFactory),SLF4J仅支持绑定一个日志实现,导致冲突抛出异常。

解决方案

  • 排查并排除冲突依赖
    1. 执行Gradle命令查看完整依赖树:./gradlew dependencies
    2. 在输出中找到包含org.slf4j:slf4j-nop的依赖项,然后在该依赖的配置中排除slf4j-nop模块,示例:
      implementation('冲突依赖的groupId:artifactId:版本号') {
          exclude group: 'org.slf4j', module: 'slf4j-nop'
      }
      
  • 检查并移除其他SLF4J绑定
    确认项目中是否引入了logback-classic之外的其他SLF4J实现(如slf4j-log4j12、slf4j-jdk14等),如有同样通过上述依赖排除方式移除。
  • 清理缓存并重新构建
    执行./gradlew clean build --refresh-dependencies清理Gradle缓存,确保冲突依赖完全移除后重新构建项目。

内容的提问来源于stack exchange,提问作者DHARMIK SONI

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.15 06:43:15