springboot项目在编译时报错:
[INFO] --- maven-compiler-plugin:3.10.1:compile (default-compile) @ gulimall-coupon ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 1 source file to E:\JavaProjects\gulimail\gulimall-coupon\target\classes
[INFO] -------------------------------------------------------------
[ERROR] COMPILATION ERROR :
[INFO] -------------------------------------------------------------
[ERROR] /E:/JavaProjects/gulimail/gulimall-coupon/src/main/java/com/atguigu/gulimall/coupon/GulimallCouponApplication.java:[3,32] 无法访问org.springframework.boot.SpringApplication
错误的类文件: C:\Users\North\.m2\repository\org\springframework\boot\spring-boot\3.0.0\spring-boot-3.0.0.jar(org/springframework/boot/SpringApplication.class)
类文件具有错误的版本 61.0, 应为 52.0
请删除该文件或确保该文件位于正确的类路径子目录中。
[INFO] 1 error
[INFO] -------------------------------------------------------------
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
经过百度了发现是springboot版本过高,项目的pom文件中我的springboot版本为3.0,而java的版本为1.8,导致不匹配报错。
原先的pom文件:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>3.0.0</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
解决办法:降低springboot的版本。
修改后的pom文件:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.8.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
编译结果:
[INFO] Copying 0 resource
[INFO]
[INFO] --- maven-compiler-plugin:3.8.1:compile (default-compile) @ gulimall-coupon ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 1 source file to E:\JavaProjects\gulimail\gulimall-coupon\target\classes
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 19.875 s
[INFO] Finished at: 2022-12-16T14:43:02+08:00
[INFO] ------------------------------------------------------------------------
参考链接:https://blog.csdn.net/simonchi/article/details/126625381