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

引入Spring BOM后出现SLF4J无提供者错误的问题求助

问题解决方法

问题根源

Spring Boot 3.1.2的BOM管理的SLF4J版本是2.x,而你使用的log4j-slf4j-impl是适配SLF4J 1.x的绑定组件。SLF4J 2.x的加载机制和1.x完全不同,旧的绑定会被系统识别为不兼容而忽略,最终导致找不到可用的SLF4J提供者,出现报错。

修复步骤

将依赖中的log4j-slf4j-impl替换为适配SLF4J 2.x的log4j-slf4j2-impl,修改后的build.gradle.kts配置如下:

dependencies {
    implementation(enforcedPlatform("org.springframework.boot:spring-boot-dependencies:3.1.2"))

    implementation("org.apache.logging.log4j:log4j-api")
    implementation("org.apache.logging.log4j:log4j-core")
    // 替换为适配SLF4J 2.x的绑定
    implementation("org.apache.logging.log4j:log4j-slf4j2-impl")

    testImplementation("org.junit.jupiter:junit-jupiter")
    testRuntimeOnly("org.junit.platform:junit-platform-launcher")
}

补充说明

  • Spring Boot BOM会自动管理log4j-slf4j2-impl的版本,无需手动指定,确保和SLF4J 2.x版本完全兼容。
  • 替换后重新执行./gradlew run,SLF4J就能正常加载Log4j作为日志实现,恢复之前的日志输出功能。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.04 00:55:59