参考来源: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. 上手并过渡到PHP7(2)——必须传递int, string, bool参数?没问题

    Type hints, Type safe 泊学实操视频 泊学原文链接PHP 7中最引人注目的新特性之一,无疑是Scalar type hints.我们可以在函数参数和返回值中使用scalar typ ...

  2. swiper中有视频时,滑动停止后视频停止播放

    我们经常能够看到在图片轮播中,穿插着视频的播放,如下图为淘宝的一个产品轮播图,放个视频能够让顾客对产品有个更全面的认识. 我们可以用swiper实现这个功能.用法就跟放图片一样,只是这里把图片换成视频 ...

  3. linux profile\bashrc\bash_profile之间的区别和联系

    /etc/profile 每个用户,首次登录时被执行: /etc/bashrc 每个运行bash shell的用户都执行此文件,当bsh被打开时,该文件被读取: ~/.bash_profile 专用于 ...

  4. FFmpeg在Android上的移植优化步骤

    http://blog.csdn.net/feixiang_john/article/details/7894188 从事多媒体软件开发的人几乎没有不知道FFmpeg的,很多视频播放器都是基于FFmp ...

  5. yasm开源汇编器分析

    https://www.google.com.hk/search?q=yasm&oq=yasm&aqs=chrome..69i57&sourceid=chrome&es ...

  6. erlang -- ios apns provider -- erlang 实现

    os apns-apple notification server 与第三方provider的通信原理网上已有很多介绍,这里不再介绍,有想了解的大家可以去IOS官网https://developer. ...

  7. 统计 fastq 文件 q20 , GC 含量的软件

    二代测序的分析过程中,经常需要统计原始下机数据的数据量,看数据量是否符合要求:另外还需要统计q20,q30,GC含量等反应测序质量的指标: 在kseq.h 的基础上稍加改造,就可以实现从fastq 文 ...

  8. PHP中如何获取网站根目录物理路径

    在php程序开发中经常需要获取当前网站的目录,我们可以通过常量定义获取站点根目录物理路径,方便在程序中使用. 下面介绍几种常用的获取网站根目录的方法. php获取网站根目录方法一: <?php ...

  9. J2SE基础:8.系统经常使用类二

    1:基础数据与封装类型之间的转型 A:基础数据类型--->封装类型(对象类型) Boolean boolean_1 = new Boolean(true); byte ---->Byte ...

  10. Linux 权限修改

    chown -R 用户名:组名 文件夹名chown -R xu:hadoop hadoop 将hadoop目录(以及其下的所有子目录/文件)的属主用户设为xu, xu 的组名为group