spring 配置註解
報錯內容:Context namespace element 'annotation-config' and its parser class [org.springframework.context.annotation.AnnotationConfigBeanDefinitionParser] are only available on JDK 1.5 and higher
原因:使用的是jdk1.8,spring會檢測jdk版本,在org.springframework.core.JdkVersion.class這個類中定義了支援的jdk版本,支援jdk1.5以上版本,
但是最多定義到了jdk1.7.
解決辦法:
1.更換jdk版本。1.5-1.7版本
2.修改JdkVersion.class這個類,再將這個類編譯替換到原來的jar包中。
修改後的檔案為:
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;
/**
* for Java 8
* *
*/
public static final int JAVA_18 = 5;
private static final String javaVersion;
private static final int majorJavaVersion;
static {
javaVersion = System.getProperty("java.version");
// for Java8
if (javaVersion.indexOf("1.8.") != -1) {
majorJavaVersion = JAVA_18;
}
else if (javaVersion.indexOf("1.7.") != -1) {
majorJavaVersion = JAVA_17;
}
else if (javaVersion.indexOf("1.6.") != -1) {
majorJavaVersion = JAVA_16;
}
else if (javaVersion.indexOf("1.5.") != -1) {
majorJavaVersion = JAVA_15;
}
else {
// else leave 1.4 as default (it's either 1.4 or unknown)
majorJavaVersion = JAVA_14;
}
}
public static String getJavaVersion() {
return javaVersion;
}
public static int getMajorJavaVersion() {
return majorJavaVersion;
}
public static boolean isAtLeastJava14() {
return true;
}
public static boolean isAtLeastJava15() {
return getMajorJavaVersion() >= JAVA_15;
}
public static boolean isAtLeastJava16() {
return getMajorJavaVersion() >= JAVA_16;
}
}