@[TOC](Error:(3, 32) java: 无法访问org.springframework.boot.SpringApplication
错误的类文件: /D:/apache-maven/localRepository/org/springframework/boot/spring-boot/3.1.0/spring-boot-3.1.0.jar!/org/springframework/boot/SpringApplication.class
类文件具有错误的版本 61.0, 应为 52.0
请删除该文件或确保该文件位于正确的类路径子目录中。)
错误原因
61.0对应jdk17,52.0对应jdk8
出现这个错误的原因是当前spring boot的版本和jdk版本不匹配
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>3.1.0</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
可以看到,spring boot的版本是3.1.0,这个版本的spring boot和jdk1.8是不匹配的,解决方案是降低spring boot的版本
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.0.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
上述错误解决之后,又出现了新的问题,可以看到有边maven侧边栏中依赖项爆红
我们对pom文件做如下修改:
- 修改前:
<dependency>
<groupId>com.mysql</groupId>
<artifactId>mysql-connector-j</artifactId>
<scope>runtime</scope>
</dependency>
- 修改后:
<dependency>
<groupId>com.mysql</groupId>
<artifactId>mysql-connector-j</artifactId>
<version>8.0.31</version>
<scope>runtime</scope>
</dependency>
重新加载依赖项,错误解决