异常信息如下:

错误: Unexpected exception parsing XML document from class path resource [spring/applicationContext-db.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 

原因:

  当前jdk版本的spring不支持注解,有两种方式解决这个问题。一是 换jdk,二是  加一个配置文件。

  这里使用的是加一个配置文件:在src文件夹加org.springframework.core包,并添加一个JdkVersion.java文件,使注解能够识别jdk8。

JdkVersion.java文件内容如下:

package org.springframework.core;

/**
* Internal helper class used to find the Java/JVM version
* that Spring is operating on, to allow for automatically
* adapting to the present platform's capabilities.
*
* <p>Note that Spring requires JVM 1.5 or higher, as of Spring 3.0.
*
* @author Rod Johnson
* @author Juergen Hoeller
* @author Rick Evans
*/
public abstract class JdkVersion { /**
* Constant identifying the 1.3.x JVM (JDK 1.3).
*/
public static final int JAVA_13 = 0; /**
* Constant identifying the 1.4.x JVM (J2SE 1.4).
*/
public static final int JAVA_14 = 1; /**
* Constant identifying the 1.5 JVM (Java 5).
*/
public static final int JAVA_15 = 2; /**
* Constant identifying the 1.6 JVM (Java 6).
*/
public static final int JAVA_16 = 3; /**
* Constant identifying the 1.7 JVM (Java 7).
*/
public static final int JAVA_17 = 4; /**
* Constant identifying the 1.8 JVM (Java 8).
*/
public static final int JAVA_18 = 5; private static final String javaVersion; private static final int majorJavaVersion; static {
javaVersion = System.getProperty("java.version");
// version String should look like "1.4.2_10"
if (javaVersion.contains("1.8.")) {
majorJavaVersion = JAVA_18;
}else if (javaVersion.contains("1.7.")) {
majorJavaVersion = JAVA_17;
}
else if (javaVersion.contains("1.6.")) {
majorJavaVersion = JAVA_16;
}
else {
// else leave 1.5 as default (it's either 1.5 or unknown)
majorJavaVersion = JAVA_15;
}
} /**
* Return the full Java version string, as returned by
* <code>System.getProperty("java.version")</code>.
* @return the full Java version string
* @see System#getProperty(String)
*/
public static String getJavaVersion() {
return javaVersion;
} /**
* Get the major version code. This means we can do things like
* <code>if (getMajorJavaVersion() < JAVA_14)</code>.
* @return a code comparable to the JAVA_XX codes in this class
* @see #JAVA_13
* @see #JAVA_14
* @see #JAVA_15
* @see #JAVA_16
* @see #JAVA_17
*/
public static int getMajorJavaVersion() {
return majorJavaVersion;
} /**
* Convenience method to determine if the current JVM is at least Java 1.4.
* @return <code>true</code> if the current JVM is at least Java 1.4
* @deprecated as of Spring 3.0 which requires Java 1.5+
* @see #getMajorJavaVersion()
* @see #JAVA_14
* @see #JAVA_15
* @see #JAVA_16
* @see #JAVA_17
*/
@Deprecated
public static boolean isAtLeastJava14() {
return true;
} /**
* Convenience method to determine if the current JVM is at least
* Java 1.5 (Java 5).
* @return <code>true</code> if the current JVM is at least Java 1.5
* @deprecated as of Spring 3.0 which requires Java 1.5+
* @see #getMajorJavaVersion()
* @see #JAVA_15
* @see #JAVA_16
* @see #JAVA_17
*/
@Deprecated
public static boolean isAtLeastJava15() {
return true;
} /**
* Convenience method to determine if the current JVM is at least
* Java 1.6 (Java 6).
* @return <code>true</code> if the current JVM is at least Java 1.6
* @deprecated as of Spring 3.0, in favor of reflective checks for
* the specific Java 1.6 classes of interest
* @see #getMajorJavaVersion()
* @see #JAVA_16
* @see #JAVA_17
*/
@Deprecated
public static boolean isAtLeastJava16() {
return (majorJavaVersion >= JAVA_16);
} }

Context namespace element 'component-scan' and its parser class [org.springframework.context.annotation.ComponentScanBeanDefinitionParser] are only available on JDK 1.5 and higher的更多相关文章

  1. 【原创】大叔经验分享(16)Context namespace element 'component-scan' and its parser class [org.springframework.context.annotation.ComponentScanBeanDefinitionParser] are only available on JDK 1.5 and higher

    今天尝试运行一个古老的工程,配置好之后编译通过,结果运行时报错: org.springframework.beans.factory.BeanDefinitionStoreException: Une ...

  2. [org.springframework.context.annotation.ComponentScanBeanDefinitionParser] are only available on JDK 1.5 and higher 问题--MyEclipse设置JDK版本

    org.springframework.beans.factory.BeanDefinitionStoreException: Unexpected exception parsing XML doc ...

  3. class [org.springframework.context.annotation.ComponentScanBeanDefinitionParser] are only available on JDK 1.5 and higher

    在搭建SSM项目时报了以下的错误: 06-Oct-2019 11:55:52.109 信息 [RMI TCP Connection(5)-127.0.0.1] org.apache.catalina. ...

  4. spring 2.5.6 错误:Context namespace element 'component-scan' and its parser class [org.springframework.context.annotation.ComponentScanBeanDefinitionParser] are only available on JDK 1.5 and higher

    在运行一个第三方公司交付的项目的时候, 出现: Caused by: java.lang.IllegalStateException: Context namespace element 'annot ...

  5. Context namespace element 'annotation-config' and its parser class [org.springframework.context.annotation.AnnotationConfigBeanDefinitionParser] are only available on JDK 1.5 and higher

    Context namespace element 'annotation-config' and its parser class [org.springframework.context.anno ...

  6. 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发现错误: Unexp ...

  7. Context namespace element 'annotation-config' and its parser class [org.springframework.context.annotation.AnnotationConfigBeanDefinitionParser]

    严重: Exception sending context initialized event to listener instance of class org.springframework.we ...

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

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

  9. [Spring Boot] Use Component Scan to scan for Bean

    Component Scan is important concept when we want to create Bean. Currently we know what, for the cla ...

随机推荐

  1. 使用Date和SimpleDateFormat类表示时间

    Date类: 使用 Date 类的默认无参构造方法创建出的对象就代表当前时间,我们可以直接输出 Date 对象显示当前的时间,显示的结果如下: Date d = new Date(); System. ...

  2. MX4_ADB

    一.Ubuntu环境1. 建立或修改文件 ~/.android/adb_usb.ini,在文件开头或末尾添加一行,内容是0x2a45. 2. 建立或修改文件 /etc/udev/rules.d/51- ...

  3. 使用Linux(CentOS)搭建SVN服务器全攻略

    虽然在windows上搭建SVN很简单,但是效能却不高,这当然是和linux相比了.然而在linux上搭建SVN却非常繁琐,所以今天这篇文章就来一步一步教您如何在Centos上搭建SVN 安装 #yu ...

  4. vcs+Makefile实现简单的testbench

    网络上找的文章,实现了一遍. 步骤如下: 1. 创建verilog代码, 包括8位加法器代码和testbench代码. adder8.v module adder8 ( input clk, inpu ...

  5. [数据结构与算法分析(Mark Allen Weiss)]二叉树的插入与删除 @ Python

    二叉树的插入与删除,来自Mark Allen Weiss的<数据结构与算法分析>. # Definition for a binary tree node class TreeNode: ...

  6. 实录分享 | 计算未来轻沙龙:揭秘AutoML技术(视频 + PPT)

    版权声明:本文为博主原创文章,未经博主同意不得转载. https://blog.csdn.net/c9Yv2cf9I06K2A9E/article/details/83542784 10 月 27 日 ...

  7. NatApp开启HTTPS访问方式

    一.首先需要到付费隧道中选择免费开启https 二.其次需要重新启动natapp服务,如下图出现两个隧道说明OK

  8. log4net.Layout.PatternLayout 用 conversion 模式格式化日志事件【翻译】

    原文地址 log4net.Layout.PatternLayout,是一个灵活的布局,配置模式字符串. 线程安全.该类型的 Public static 成员对多线程操作是安全的.实例成员不保证线程安全 ...

  9. shell相关知识点

    一.shell shell中如何支持多线程 shell中如何操作数据库 shell编程中的控制 判断语句 cut sed awk sort exec xargs shell中常用表达 shell处理字 ...

  10. Spring4学习笔记二:Bean配置与注入相关

    一:Bean的配置形式 基于XML配置:在src目录下创建 applicationContext.xml  文件,在其中进行配置. 基于注解配置:在创建bean类时,通过注解来注入内容.(这个不好,因 ...