项目使用的 Spring Boot 升级到 3.0.5 版本
编译的时候报错如下:
1 2 3 4 |
Error:(5, 32) java: 无法访问org.springframework.lang.NonNull 错误的类文件: /Users/xxxx/.m2/repository/org/springframework/spring-core/6.0.7/spring-core-6.0.7.jar(org/springframework/lang/NonNull.class) 类文件具有错误的版本 61.0, 应为 52.0 请删除该文件或确保该文件位于正确的类路径子目录中。 |
或者:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
OpenJDK 64-Bit Server VM warning: Options -Xverify:none and -noverify were deprecated in JDK 13 and will likely be removed in a future release. Connected to the target VM, address: '127.0.0.1:54101', transport: 'socket' Exception in thread "main" java.lang.UnsupportedClassVersionError: org/springframework/boot/SpringApplication has been compiled by a more recent version of the Java Runtime (class file version 61.0), this version of the Java Runtime only recognizes class file versions up to 58.0 at java.base/java.lang.ClassLoader.defineClass1(Native Method) at java.base/java.lang.ClassLoader.defineClass(ClassLoader.java:1017) at java.base/java.security.SecureClassLoader.defineClass(SecureClassLoader.java:151) at java.base/jdk.internal.loader.BuiltinClassLoader.defineClass(BuiltinClassLoader.java:821) at java.base/jdk.internal.loader.BuiltinClassLoader.findClassOnClassPathOrNull(BuiltinClassLoader.java:719) at java.base/jdk.internal.loader.BuiltinClassLoader.loadClassOrNull(BuiltinClassLoader.java:642) at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:600) at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178) at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:522) at com.xxx.xxx.xxx.MainServiceApplication.main(MainServiceApplication.java:12) Disconnected from the target VM, address: '127.0.0.1:54101', transport: 'socket' |
原因
SpringBoot 使用了 3.0 或者 3.0 以上,因为 Spring 官方发布从 Spring 6 以及 SprinBoot 3.0 开始最低支持 JDK17,所以仅需将 SpringBoot 版本降低为 3.0 以下即可。