項目中用的是spring低版本(2.5.6),今天用jre 8測試了一下,發現錯誤:
Unexpected exception parsing XML document from class path resource [applicationContext-dao.xml]; nested exception isJava.lang.IllegalStateException: Context namespace element ‘annotation-config’ and its parser class [org.springframework.context.annotation.AnnotationConfigBeanDefinitionParser] are only available on JDK 1.5 and higherjava
看源碼是org.springframework.context.annotation.AnnotationConfigBeanDefinitionParser自動檢測,jdk版本檢測時須要jre1.5以上版本,可是JdkVersion只檢查到了1.7,jre1.8 時不匹配任何jdk,按以下方法處理,能夠解決問題。spring
一、在項目中建立一個package爲org.springframework.core
二、在該package下面新建JdkVersion.java,內容以下:app
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 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; } } }
三、到項目的WEB-INF/classes 下面找到對應的package中的JdkVersion.class文件
四、將項目中的spring-core-2.5.6.jar拷貝出來打開,而後將JdkVersion.class替換jar包中的該文件。
五、將修改後的spring-core-2.5.6.jar再覆蓋到項目中。測試
這樣,再啓動項目就不會出現錯誤了。spa