异常:java.lang.IllegalStateException: Context namespace element ‘annotation-config’ and its parser class [org.springframework.context.annotation.AnnotationConfigBeanDefinitionParser] are only available on JDK 1.5 and higher**
当前jdk版本的spring不支持注解,所以要换jdk,或者加一个配置文件。
我一般是在src文件夹加org.springframework.core包,并添加一个JdkVersion.java文件。使注解能够识别jdk8。
JdkVersion.java:
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 JdkVersion()
{
}
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;
}
public static boolean isAtLeastJava17()
{
return getMajorJavaVersion() >= 4;
}
public static boolean isAtLeastJava18()
{
return getMajorJavaVersion() >= 5;
}
static
{
// version String should look like "1.4.2_10"
if (javaVersion.contains("1.8.")) {
majorJavaVersion = JAVA_18;
System.out.println("JAVA_VERSION: "+javaVersion);
}
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;
}
}
相关学习资料:
https://stillcoolme.iteye.com/blog/2314109
https://stackoverflow.com/questions/23813369/spring-java-error-namespace-element-annotation-config-on-jdk-1-5-and-high