参考来源: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 = ;
public static final int JAVA_14 = ;
public static final int JAVA_15 = ;
public static final int JAVA_16 = ;
public static final int JAVA_17 = ;
//for jre 1.8
public static final int JAVA_18 = ;
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() >= ;
}
public static boolean isAtLeastJava16() {
return getMajorJavaVersion() >= ;
}
static {
//for jre 1.8
if (javaVersion.indexOf("1.8.") != -) {
majorJavaVersion = ;
}else if (javaVersion.indexOf("1.7.") != -) {
majorJavaVersion = ;
} else if (javaVersion.indexOf("1.6.") != -) {
majorJavaVersion = ;
} else if (javaVersion.indexOf("1.5.") != -) {
majorJavaVersion = ;
} else {
majorJavaVersion = ;
}
}
}

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再覆盖到项目中。

这样就解决版本问题了。

spring低版本报错:java.lang.IllegalStateException: Context namespace element ‘annotation-config’ and its parser class [*] are only available on的更多相关文章

  1. nested exception is java.lang.IllegalStateException: Context namespace element 'annotation-config' a

    公司还用的是spring低版本,今天用jre 8测试了一下,发现错误: Unexpected exception parsing XML document from class path resour ...

  2. Spring Scheduled定时任务报错 java.lang.IllegalStateException: Encountered invalid @Scheduled method 'xxx': For input string: "2S"

    报错信息如下: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'ding ...

  3. Spring Boot单元测试报错java.lang.IllegalStateException: Could not load TestContextBootstrapper [null]

    1 报错描述 java.lang.IllegalStateException: Could not load TestContextBootstrapper [null]. Specify @Boot ...

  4. 云笔记项目- 上传文件报错"java.lang.IllegalStateException: File has been moved - cannot be read again"

    在做文件上传时,当写入上传的文件到文件时,会报错“java.lang.IllegalStateException: File has been moved - cannot be read again ...

  5. eclipse启动报错java.lang.IllegalStateException: LifecycleProcessor not initialized - call 'refresh' befo

    报错: java.lang.IllegalStateException: LifecycleProcessor not initialized - call 'refresh' before invo ...

  6. Android - 错: java.lang.IllegalStateException: Already attached

    错: java.lang.IllegalStateException: Already attached 本文地址: http://blog.csdn.net/caroline_wendy 可能原因: ...

  7. 解决spring boot启动报错java.lang.NoClassDefFoundError: ch/qos/logback/classic/Level

    解决spring boot启动报错java.lang.NoClassDefFoundError: ch/qos/logback/classic/Level 学习了:https://blog.csdn. ...

  8. 使用RestTemplate时报错java.lang.IllegalStateException: No instances available for 127.0.0.1

    我在RestTemplate的配置类里使用了 @LoadBalanced@Componentpublic class RestTemplateConfig { @Bean @LoadBalanced ...

  9. springboot测试启动报错java.lang.IllegalStateException: Unable to find a @SpringBootConfiguration, you need to use @ContextConfiguration or @SpringBootTest(classes=...) with your test

    springboot测试启动报错: java.lang.IllegalStateException: Unable to find a @SpringBootConfiguration, you ne ...

随机推荐

  1. 消息中间件系列之Java API操作ActiveMQ

    一.依赖 <dependency> <groupId>org.apache.activemq</groupId> <artifactId>activem ...

  2. 关于PHP的特点

    魔术方法 当一个对象引用变量调用一个没有定义的属性或方法时,可以这一个函数.当发生这种情况时调用这种函数.

  3. Google Analytics10条有用教程(转)

    几乎每个网站都会统计自身的浏览状况:日IP.PV.跳出率.转换率.浏览者属性等等.了解这些数据有助于更好地了解浏览者的属性.知道网站在什么地方存在缺陷,为更好地提供服务.提高网站收入都有所帮助. 对于 ...

  4. 你是否有遇到过某个实体类字段(属性)过多的情况,不想每次点的话戳进来(C# 反射)

    贴上一段代码: bureaucraticEntities apply = new bureaucraticEntities(); Type tapp= app.GetType(); Type ttmp ...

  5. opengl 裁剪平面

    原帖地址:http://blog.sina.com.cn/s/blog_5ff6097b0100xqvr.html void glClipPlane(GLenum plane, const GLdou ...

  6. [精]Odoo 8.0深入浅出开发教程-模块开发基础

    參考资料点击这里. 构建Odoo模块 模块组成 业务对象 业务对象声明为Python类, 由Odoo自己主动加载. 数据文件 XML或CSV文件格式, 在当中声明了元数据(视图或工作流).配置数据(模 ...

  7. 【HMM】隐马尔科夫模型

    http://www.hankcs.com/nlp/hmm-and-segmentation-tagging-named-entity-recognition.html

  8. XLua系统学习

    官方网站:https://github.com/Tencent/xLua 学习手册:http://manual.luaer.cn/ 技术博客: http://blog.csdn.net/column/ ...

  9. linux中,ssh实现免密自动登录到远程主机,ssh信任的实现

    需求描述: 平时使用ssh的时候,一般使用ssh都是通过用户名和密码登录到远程主机上, 然后执行一些命令,远程登录过程中,需要手动的输入密码(提示输入密码之后), 但是,在实际的应用过程中,涉及到让脚 ...

  10. opencv-从图像旋转学习Mat数据訪问

    先看一个简单的样例 代码: // ConsoleApplication3_6_23.cpp : Defines the entry point for the console application. ...