先看出现的错误:
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
I have Spring/Java App that is compiled with Compiler compliance level 1.5.
解决办法:
在项目下新建一个包,包名是 org.springframework.core
然后在包下新建一个类 JdkVersion
JdkVersion的内容如下: ,保存后,重新运行即可。
package org.springframework.core;
public abstract 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;
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 {
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;
}
}
}