问题:配置Spring的时候容易发生如题的这样一个经常性的错误,错误如下(以context为例)

org.springframework.beans.factory.xml.XmlBeanDefinitionStoreException:
Line 8 in XML document from class path resource [applicationContext.xml] is invalid;
nested exception is org.xml.sax.SAXParseException;
lineNumber: 8; columnNumber: 47; cvc-complex-type.2.4.c:
通配符的匹配很全面, 但无法找到元素 'context:component-scan' 的声明。

再看看beans的约束:

<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:p="http://www.springframework.org/schema/p"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
>

咦?这不是有context的声明吗,

没错,不过还少了一些东西,那就是关于context的xsi的模式地址 xsi:schemaLocation 的更新

  1. xmlns:全名是xml namespace,也即是为当前的这个xml指定命名空间。

  2. xmlns:xsi:是指当前xml所要遵循的标签规范.

  3. 如上xmlns配上hdp, xsi, aop, cache, context, mvc…都是当前xml要使用到的一个标签,后面就是指定标签所要遵循的规范。

  4. xsi:schemaLocation:指定的命名空间对应的验证文件,用来定义xml schema的地址,也就是xml书写时需要遵循的语法,用于声明了目标命名空间的模式文档。。两部分组成,前面部分就是命名空间的名字,后面是xsd(xmlschema)文档的地址,也是就表示把定义这个命名空间的schema文件给引用进来,好让eclipse这类型工具能够解析和验证你的xml文件是否符合语法规范。简单来说就是声明了目标命名空间的模式文档。

解决方案:除了要添加xmlns:XXX之外,还需要添加对应的xsi:schemaLocation【可以去google一下所需要的xsi:schemaLocation

如下:

<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:p="http://www.springframework.org/schema/p"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd"
>

Spring:通配符的匹配很全面, 但无法找到元素 XXXXX' 的声明的更多相关文章

  1. 关于spring”通配符的匹配很全面, 但无法找到元素 'context:component-scan' 的声明“的错误

    关于spring配置的问题 近日学习spring时遇到了这个问题: org.springframework.beans.factory.xml.XmlBeanDefinitionStoreExcept ...

  2. nested exception is org.xml.sax.SAXParseException; lineNumber: 8; columnNumber: 56; cvc-complex-type.2.4.c通配符的匹配很全面, 但无法找到元素 'dubbo:application' 的声明

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

  3. 通配符的匹配很全面, 但无法找到元素 'cache:advice' 的声明

    EB-INF\classes\spring-jdbc.xml] is invalid; nested exception is org.xml.sax.SAXParseException; lineN ...

  4. idea调试SpringMvc, 出现:”通配符的匹配很全面, 但无法找到元素 'mvc:annotation-driven' 的声明“错误的解决方法

    调试json格式输出,出现以下错误: HTTP Status 500 - Servlet.init() for servlet HelloDispatcher threw exception   ty ...

  5. dubbo 常见错误 通配符的匹配很全面, 但无法找到元素 'dubbo:application' java.lang.reflect.MalformedParameterizedTypeException 通配符的匹配很全面, 但无法找到元素 'dubbo:application' 的声明。 Unsupported major.minor version 52.0 (unable to l

    dubbo 常见错误 1. Caused by: java.lang.reflect.MalformedParameterizedTypeException 启动时报错,原因是dubbo 依赖 spr ...

  6. springMVC:通配符的匹配很全面, 但无法找到元素 'mvc:annotation-driven' 的声明

    转自:http://blog.csdn.net/tolcf/article/details/50845483 报错信息:通配符的匹配很全面, 但无法找到元素 'mvc:annotation-drive ...

  7. 通配符的匹配很全面, 但无法找到元素 'mvc:annotation-driven' 的声明

    通配符的匹配很全面, 但无法找到元素 'mvc:annotation-driven' 的声明 错误原因是springmvc中的约束信息不对 <beans xmlns="http://w ...

  8. 通配符的匹配很全面, 但无法找到元素 'tx:annotation-driven' 的声明

    启动Tomcat时报错,通配符的匹配很全面, 但无法找到元素 'tx:annotation-driven' 的声明,报错如下 1.从报错可以看到找不到元素   tx:annotation-driven ...

  9. Spring常见问题-通配符的匹配很全面, 但无法找到元素 'aop:aspectj-autoproxy' 的声明

随机推荐

  1. 支付宝SDK的使用方法

    前奏 现在随着移动开发的快速发展,越来越多的应用要求在线支付功能.最近做了一个关于支付宝支付功能的应用,在使用支付宝的过程中,遇到一些不必要的弯路,因此,写了这篇文章总结一下关于ios开发如何使用支付 ...

  2. 跳出NSDate

    感觉任何语言关于时间的格式化处理,时区的处理都是多的,最近被NSDate的各种问题坑了好久 先看看关于NSDate自己的问题 1.NSDate NSDate获取当前时间 NSDate *date=[N ...

  3. Chrome 默认样式 (user agent stylesheetbody) 优先级变高的问题

    解决方法:只需要在页面的<HTML>标签前添加声明即可. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional ...

  4. wcf 开发 1

    1.创建wcf应用程序 2.生成服务,启动 3.使用工具生成 文件如下: 4.新增加winform程序项目,并添加文件 service1.cs 修改app.config 5.代码调用 private ...

  5. Python 去掉文本中空行

    pandas 操作csv文件时,一直报错,排查后发现csv文本中存在很多“空行”: So 需要把空行全部去掉: def clearBlankLine(): file1 = open('text1.tx ...

  6. 《CNI specification》翻译

    Overview 本文提出了一个通用的基于插件的Linux容器网络解决方案,容器网络接口,CNI.它脱胎于旨在满足大多数rtk网络设计的rtk Networking Proposal. 首先,我们对如 ...

  7. Leetcode 之 Keys Keyboard

    1. 2 Keys Keyboard 先把dp的最小不走都设置为无穷大(Integer.MAX_VALUE),初始化条件:dp[0] = dp[1] = 0,状态转移方程为dp[i] = Math.m ...

  8. Remote System Upgrade With Cyclone III Devices

    系统设计者会遇到较短的设计周期.标准发展和系统调度的挑战,飓风III系列支持远程系统更新,通过其固有的重编程功能和专有电路来克服以上问题.远程系统更新帮助传递系统性能增强和bug修复,避免了昂贵的召回 ...

  9. 【Flask】Flask Restful api

    ### 安装: Flask-Restful需要在Flask 0.8以上的版本,在Python2.6或者Python3.3上运行.通过pip install flask-restful即可安装. ### ...

  10. dubbo应用

    一.安装配置 cd /usr/local/ wget http://www.apache.org/dist/zookeeper/zookeeper-3.4.6/zookeeper-3.4.6.tar. ...