Spring has only available on JDK 1.5 and higher error detailed solution!!!
Summary:
Previously, when learning Spring, there was a problem incompatible with the jdk version, and an error will be reported at runtime:
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
After checking the source code of the JdkVersion class, it is found that Spring can only recognize jdk1.7, but not the later version. There are two solutions to the problem:
1. Directly change the JDK to jdk1.7 or lower, but it may not be supported for other jar packages (I have this situation anyway)
2. The second way is to manually modify spring's jar package. In the org.springframework.core directory, there is a JdkVersion.class. You can refer to the package path and write a new JdkVersion.java. (recommended)
The modified JdkVersion.java file is as follows:
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; //You can also change the support for later JDK by referring to the template //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; } } }
Next, let's take a look at the specific steps to modify the class source code in Jar package. Refer to my other blog:
https://blog.csdn.net/HuanglnQuan/article/details/89205223