1.调整 Spring Boot 版本
由于 Spring Boot 3.x 最低要求 JDK 17,所以如果要使用 JDK 8,需要把 spring-boot-starter-parent
的版本降低到 2.7.x 系列,这个系列是支持 JDK 8 的。示例如下:
<parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>2.7.15</version> <!-- 选择合适的 2.7.x 版本 --> <relativePath/> <!-- lookup parent from repository --> </parent>
2.明确 JDK 版本配置
把 maven.compiler.source
和 maven.compiler.target
都设置为 1.8
,以此指定编译时使用的 Java 版本是 JDK 8。同时,将 java.version
也修改为 1.8
,保证整个项目版本配置的一致性。示例如下:
<properties> <java.version>1.8</java.version> <maven.compiler.source>1.8</maven.compiler.source> <maven.compiler.target>1.8</maven.compiler.target> </properties>