Caused by: java.lang.UnsupportedClassVersionError: org/springframework/context/annotation/ClassPathBeanDefinitionScanner : Unsupported major.minor version 52.0 (unable to load class org.springframework.context.annotation.ClassPathBeanDefinitionScanner)
报错原因:运行环境的jdk版本低于项目需要的jdk版本
在构建项目时也可以得到提示:Warning:java: D:\mavenRepositories\Crm-UCCP\smp_com\V3.x\smp_com-V3.x.jar(com/tydic/smp/entity/UsersEntity.class): 主版本 52 比 51 新, 此编译器支持最新的主版本。
建议升级此编译器。
解决方法:将jdk版本统一从1.7升级到1.8,具体过程就是在idea中对jdk版本的各种设置,这里就不记录了。
--------------------------------------------------------------------------------------------------------------------------------------------------------------
jdk升级到1.8之后,重新启动项目报错:
Caused by: java.lang.IllegalStateException: Context namespace element 'component-scan' and its parser class [org.springframework.context.annotation.ComponentScanBeanDefinitionParser] are only available on JDK 1.5 and higher
报错原因:Spring版本过低,不支持jdk1.8
解决方法:修改spring的jar包,在org.springframework.core目录下,有一个JdkVersion.class,自己参照包路径,重新写一个JdkVersion.java。
修改后的JdkVersion.java文件如下:
package org.springframework.core; public class JdkVersion { public static final int JAVA_13 = 0; public static final int JAVA_14 = 1; public static final int JAVA_15 = 2; public static final int JAVA_16 = 3; public static final int JAVA_17 = 4; //还可以参照该模板更改对更高版本JDK的支持 //for jre 1.8 public static final int JAVA_18 = 5; private static final String javaVersion = System.getProperty("java.version"); private static final int majorJavaVersion; public static String getJavaVersion() { return javaVersion; } public static int getMajorJavaVersion() { return majorJavaVersion; } public static boolean isAtLeastJava14() { return true; } public static boolean isAtLeastJava15() { return getMajorJavaVersion() >= 2; } public static boolean isAtLeastJava16() { return getMajorJavaVersion() >= 3; } static { //for jre 1.8 if (javaVersion.indexOf("1.8.") != -1) { majorJavaVersion = 5; } else if (javaVersion.indexOf("1.7.") != -1) { majorJavaVersion = 4; } else if (javaVersion.indexOf("1.6.") != -1) { majorJavaVersion = 3; } else if (javaVersion.indexOf("1.5.") != -1) { majorJavaVersion = 2; } else { majorJavaVersion = 1; } } }