在通过IDEA配置自动生成springboot项目后,启动时出现下面问题。
Error:(3, 32) java: 无法访问org.springframework.boot.SpringApplication
错误的类文件: /Users/cailongsheng/apache-maven-3.3.9/repository/org/springframework/boot/spring-boot/3.0.5/spring-boot-3.0.5.jar!/org/springframework/boot/SpringApplication.class
类文件具有错误的版本 61.0, 应为 52.0
请删除该文件或确保该文件位于正确的类路径子目录中。
Error:(3, 32) java: 无法访问org.springframework.boot.SpringApplication
错误的类文件: /Users/cailongsheng/apache-maven-3.3.9/repository/org/springframework/boot/spring-boot/3.0.5/spring-boot-3.0.5.jar!/org/springframework/boot/SpringApplication.class
类文件具有错误的版本 61.0, 应为 52.0
请删除该文件或确保该文件位于正确的类路径子目录中。
解决办法如下:其实是自动生成在pom中Spring Boot的父级依赖版本不匹配导致
org.springframework.boot
spring-boot-starter-parent
3.0.5
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>3.0.5</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
只用把这个3.0.5改小一点就行,例如2.7.3
然后刷新一下依赖,重新编译启动就好了。