今天看视频选Spring MVC ,但是启动服务器,所有XML文件都报一样的错, org.springframework.beans.factory.BeanDefinitionStoreException: Unexpected exception parsing XML document from ServletContext resource [/WEB-INF/hib-config.xml]; nested exception is 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 at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.doLoadBeanDefinitions(XmlBeanDefinitionReader.java:420) at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:342)
org.springframework.context.annotation.ComponentScanBeanDefinitionParser是JDK 1.5和更高版本上可用
org.springframework.context.annotation.AnnotationConfigBeanDefinitionParser自動檢測,jdk版本檢測時需要jre1.5以上版本,但是JdkVersion只檢查到了1.7,jre1.8 時不匹配任何jdk, 修正如下,問題解决
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; } } }我也遇到了同样的问题。之前在jdk1.6下正常运行的项目,迁移到jdk8.0以后就出现了这个问题!
|