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

Spring Boot项目无法访问jakarta.servlet.FilterChain类版本兼容问题求助

解决方案

1. 移除外部Tomcat 11的类路径引用

Spring Boot自带嵌入式Tomcat,无需手动添加外部Tomcat的类库到项目类路径:

  • 打开IntelliJ的Run/Debug Configurations,找到你的Spring Boot启动配置,切换到Classpath标签,检查并移除所有指向C:\Program Files\Apache Software Foundation\Tomcat 11.0\lib的条目。
  • 进入Project Structure → Libraries,如果存在Tomcat 11相关的库,直接删除。

2. 修复依赖版本混乱问题

你的pom.xml存在多版本Spring Boot组件冲突,这是核心问题之一:

  • 添加Spring Boot Parent依赖统一版本管理,放在<dependencies>之前:
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.4.2</version>
        <relativePath/>
    </parent>
    
  • 删除以下依赖的手动版本声明,让Parent自动管理兼容版本:
    • spring-boot-starter-mail的version
    • spring-security-config的version
    • tomcat-embed-core的version
  • 移除手动添加的jakarta.servlet-api依赖,因为spring-boot-starter-web已经包含了适配版本的Servlet API,重复添加会导致冲突。

3. 匹配JDK版本

Spring Boot 2.4.x支持JDK 8/11/16,而Tomcat 11的类文件是JDK 21编译的(版本65),完全不兼容:

  • 在IntelliJ中设置项目JDK:File → Project Structure → Project,将Project SDK设为JDK 8或11,Project language level对应设置为8或11。
  • 在pom.xml中添加Maven编译配置,确保编译版本一致:
    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <configuration>
                    <source>11</source> <!-- 对应你的JDK版本,比如8 -->
                    <target>11</target>
                </configuration>
            </plugin>
        </plugins>
    </build>
    

4. 重新构建项目

  • 执行Maven命令:mvn clean install -U,强制更新依赖并清理旧编译文件。
  • 重启IntelliJ:File → Invalidate Caches... → Invalidate and Restart,清除IDE缓存。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.13 09:05:27