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

Spring Boot项目运行报错问题求助

解决方案

1. 确认Spring Boot版本与JDK兼容性

Spring Boot 3.x及以上版本强制要求JDK 17+,先检查pom.xml里的父依赖版本:

<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>3.x.x</version> <!-- 3.x版本必须用JDK17+ -->
</parent>

如果是2.x版本,JDK 8/11都可,但要保证Maven配置的版本和本地JDK一致。

2. 统一IDE与Maven的JDK配置

只改Maven构建版本不够,要确保IDE全局和项目的JDK都是17:

  • IDEA:File > Project Structure,检查Project SDK和Modules SDK都选JDK 17;
  • Eclipse:Window > Preferences > Java > Installed JREs,添加并勾选JDK 17,再到项目属性里指定;
  • 补充Maven全局配置(settings.xml):
    <profile>
        <id>jdk17</id>
        <activation>
            <activeByDefault>true</activeByDefault>
            <jdk>17</jdk>
        </activation>
        <properties>
            <maven.compiler.source>17</maven.compiler.source>
            <maven.compiler.target>17</maven.compiler.target>
        </properties>
    </profile>
    

3. 明确项目的Maven编译器插件版本

在pom.xml中直接指定编译参数,避免版本冲突:

<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.11.0</version>
            <configuration>
                <source>17</source>
                <target>17</target>
                <encoding>UTF-8</encoding>
            </configuration>
        </plugin>
    </plugins>
</build>

4. 清理缓存并重新构建

执行Maven命令彻底清理旧构建文件:

mvn clean install -U

如果还是报错,把截图里的具体错误日志文本贴出来,能更快定位问题。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.22 21:13:19