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

Spring Boot 3.0.5+Lombok整合SLF4J警告难消及Maven打包失败求助

解决Spring Boot 3.0.5 SLF4J警告及Maven构建失败问题

问题根源分析

Spring Boot 3.x依赖SLF4J 2.x版本,但你的项目存在两个核心冲突点:

  1. 手动添加的slf4j-nop依赖与Spring Boot自带的日志实现(Logback)冲突
  2. 第三方依赖json-simple 1.1引入了SLF4J 1.x绑定,导致版本不兼容,触发警告并阻断Maven构建流程

具体解决方案

1. 移除手动添加的SLF4J依赖

删除pom.xml中以下代码块:

<!-- https://mvnrepository.com/artifact/org.slf4j/slf4j-nop -->
<dependency>
    <groupId>org.slf4j</groupId>
    <artifactId>slf4j-nop</artifactId>
</dependency>

Spring Boot的spring-boot-starter-web、spring-boot-starter-data-jpa等starter已默认包含spring-boot-starter-logging,自带Logback作为SLF4J的实现提供者,无需手动添加SLF4J相关依赖。

2. 排除第三方依赖中的旧版SLF4J

修改json-simple的依赖配置,排除其自带的SLF4J 1.x依赖:

<dependency>
    <groupId>com.googlecode.json-simple</groupId>
    <artifactId>json-simple</artifactId>
    <version>1.1</version>
    <exclusions>
        <exclusion>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-api</artifactId>
        </exclusion>
    </exclusions>
</dependency>

3. 验证依赖树(可选)

执行命令检查项目依赖树,确认所有SLF4J相关依赖版本为2.x:

mvn dependency:tree | grep slf4j

Spring Boot 3.0.5对应的SLF4J版本为2.0.7,输出中需确保无1.x版本的SLF4J依赖。

4. 清理并重新构建

执行以下命令清理Maven缓存并重新构建项目:

mvn clean install -U

-U参数强制更新快照依赖,确保所有依赖为兼容版本。

额外说明

若问题仍存在,检查其他第三方依赖是否也引入了旧版SLF4J,重复步骤2进行排除即可。Spring Boot的依赖管理会自动协调SLF4J版本,只要避免手动引入冲突依赖或旧版绑定,就能消除警告并正常生成Jar包。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.13 12:16:11