我想在 Intellij Idea 上创建一个 Spring Boot 项目,我选择 Java 8 和 Java 1.8 sdk,但是当我打开 pom.xml 时,我看到我的 java 版本是 17!?这怎么可能?
当我运行我的项目时,我看到下面这条消息,我的 jar 版本如何 6.0.7 ?;
java: cannot access org.springframework.http.HttpStatus
bad class file: /C:/Users/eegee/.m2/repository/org/springframework/spring-web/6.0.7/spring-web-6.0.7.jar!/org/springframework/http/HttpStatus.class
class file has wrong version 61.0, should be 52.0
Please remove or make sure it appears in the correct subdirectory of the classpath.
您可以检查或执行三件事:
pom.xml
(并将其应用到所有模块)。
<properties>
<java.version>1.8</java.version>
</properties>
maven-compiler-plugin
,您还想检查其属性中的版本:
<properties>
<maven.compiler.target>1.8</maven.compiler.target>
<maven.compiler.source>1.8</maven.compiler.source>
</properties>
或者,在插件配置本身中指定它:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
您还可以参考
${java.version}
中的 pom.xml
文件。
如果您使用 JDK >17 和最新的库(例如 Spring 6),请使用版本 5.1.0(发行说明)。如果您使用的是较旧的 JDK 或库,请使用版本 4.44.0(文档)。 看一下
在我看来,ypu应该使用4.44.0 当我纠正问题时它对我有用