zoukankan      html  css  js  c++  java
  • spring低版本报错:java.lang.IllegalStateException: Context namespace element ‘annotation-config’ and its parser class [*] are only available on

    参考来源:http://blog.csdn.net/sunxiaoyu94/article/details/50492083

    使用spring低版本(2.5.6),使用jre 8发现错误: 

    Unexpected exception parsing XML document from class path resource [applicationContext-dao.xml]; 
    nested exception is 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

    看源码是org.springframework.context.annotation.AnnotationConfigBeanDefinitionParser自动检测,jdk版本检测时需要jre1.5以上版本,

    但是JdkVersion只检查到了1.7,jre1.8 时不匹配任何jdk,按如下方法处理,可以解决问题。

    1、在项目中创建一个package为org.springframework.core 
    2、在该package下面新建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;  
        //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;  
            }  
        }  
    }  

    3、到项目的WEB-INF/classes 下面找到对应的package中的JdkVersion.class文件 

    4、将项目中的spring-core-2.5.6.jar拷贝出来打开,然后将JdkVersion.class替换jar包中的该文件。(可以使用win rar打开jar包)

    5、将修改后的spring-core-2.5.6.jar再覆盖到项目中。

    这样就解决版本问题了。

  • 相关阅读:
    codeforces_1075_C. The Tower is Going Home
    leetcode_Stone Game_dp_思维
    leetcode_Counting Bits_dp
    Divide and Conquer_1.最大连续子数组
    python_MachineLearning_感知机PLA
    IIS中启用gzip压缩(网站优化)
    asp.net运行机制图
    asp.net 的那点事(2、浏览器和一般处理程序)
    asp.net 的那点事(1、当用户在浏览器地址栏输入了网址后,发生了什么?)
    android环境搭配 运行android sdk manager时出现错误问题解决
  • 原文地址:https://www.cnblogs.com/taiguyiba/p/8125176.html
Copyright © 2011-2022 走看看