关于spring”通配符的匹配很全面, 但无法找到元素 'context:component-scan' 的声明“的错误
关于spring配置的问题
近日学习spring时遇到了这个问题:
- org.springframework.beans.factory.xml.XmlBeanDefinitionStoreException: Line 12 in XML document from URL [file:/F: /workspace/spring/target/classes /applicationContext.xml] is invalid; nested exception is org.xml.sax.SAXParseException; lineNumber: 12; columnNumber: 55; cvc- complex-type.2.4.c: 通配符的匹配很全面, 但无法找到元素 'context:component-scan' 的声明。
报错如下:
- 17:21:22,400 ERROR main context.ContextLoader:331 - Context initialization failed
- org.springframework.beans.factory.xml.XmlBeanDefinitionStoreException: Line 14 in XML document from URL [file:/F:
/workspace/spring/target/classes
/applicationContext.xml] is invalid; nested exception is org.xml.sax.SAXParseException; lineNumber: 14; columnNumber: 54; cvc-
complex-type.2.4.c: 通配符的匹配很全面, 但无法找到元素 'context:component-scan' 的声明。 - at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.doLoadBeanDefinitions(XmlBeanDefinitionReader.java:399)
- at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:336)
- at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:304)
- at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:181)
- at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:217)
- at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:188)
- at org.springframework.web.context.support.XmlWebApplicationContext.loadBeanDefinitions(XmlWebApplicationContext.java:125)
- at org.springframework.web.context.support.XmlWebApplicationContext.loadBeanDefinitions(XmlWebApplicationContext.java:94)
- at org.springframework.context.support.AbstractRefreshableApplicationContext.refreshBeanFactory(AbstractRefreshableApplicationContext.java:129)
- at org.springframework.context.support.AbstractApplicationContext.obtainFreshBeanFactory(AbstractApplicationContext.java:537)
- at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:452)
- at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:403)
- at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:306)
- at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:106)
- at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4135)
- at org.apache.catalina.core.StandardContext.start(StandardContext.java:4630)
- at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1045)
- at org.apache.catalina.core.StandardHost.start(StandardHost.java:785)
- at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1045)
- at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:445)
- at org.apache.catalina.startup.Embedded.start(Embedded.java:825)
- at org.codehaus.mojo.tomcat.AbstractRunMojo.startContainer(AbstractRunMojo.java:558)
- at org.codehaus.mojo.tomcat.AbstractRunMojo.execute(AbstractRunMojo.java:255)
- at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:133)
- at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:208)
- at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:153)
- at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:145)
- at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:108)
- at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:76)
- at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build(SingleThreadedBuilder.java:51)
- at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:116)
- at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:361)
- at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:155)
- at org.apache.maven.cli.MavenCli.execute(MavenCli.java:584)
- at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:213)
- at org.apache.maven.cli.MavenCli.main(MavenCli.java:157)
- at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
- at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
- at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
- at java.lang.reflect.Method.invoke(Method.java:483)
- at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:289)
- at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:229)
- at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:415)
- at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:356)
查了好多资料,发现是applicationContext.xml文件有点小问题。
报错时的文件头:
- <?xml version="1.0" encoding="UTF-8"?>
- <beans xmlns="http://www.springframework.org/schema/beans"
- xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xmlns:tx="http://www.springframework.org/schema/tx"
- xmlns:aop="http://www.springframework.org/schema/aop"
- xmlns:context="http://www.springframework.org/schema/context"
- xmlns:jee="http://www.springframework.org/schema/jee"
- xsi:schemaLocation="
- http://www.springframework.org/schema/beans
- http://www.springframework.org/schema/beans/spring-beans.xsd">
改为:
- <?xml version="1.0" encoding="UTF-8"?>
- <beans xmlns="http://www.springframework.org/schema/beans"
- <span style="white-space:pre"> </span>xmlns:context="http://www.springframework.org/schema/context"
- <span style="white-space:pre"> </span>xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- <span style="white-space:pre"> </span>xmlns:aop="http://www.springframework.org/schema/aop"
- <span style="white-space:pre"> </span>xmlns:mvc="http://www.springframework.org/schema/mvc"
- <span style="white-space:pre"> </span>xmlns:jee="http://www.springframework.org/schema/jee"
- <span style="white-space:pre"> </span>xmlns:tx="http://www.springframework.org/schema/tx"
- <span style="white-space:pre"> </span>xsi:schemaLocation="
- http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
- http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
- http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd
- http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd
- http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee.xsd
- http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd">
就OK了~(*^__^*) ,注:不要拷贝上面配置,要根据自己项目缺少的schema而添加
原因:
我这个原因是有些“schemaLocation”没有写。把对应的加上就可以了。其根本原因是spring启动是时候要通过相应的xsd文件来检验xml文件,找不到相应的xsd文件的时候就会报错。
那么spring是如何加载xsd文件的呢?
spring是默认从本地加载xsd文件的,举个栗子:我们打开spring-context的jar包,找到spring.schemas这个文件
然后在org/springframework/context/config目录下可以找到这些xsd文件。默认加载的就是这些文件。
spring这一点细节做得比较好,把所有版本的xsd文件都放进来了,无论在spring配置文件中写哪个版本的schemaLocation,都能找得到。如果不写schemaLocation的版本号是,默认是当前版本。
解决办法:
检查spring配置文件里有没有配相应的schema配置,补充上就可以了
关于spring”通配符的匹配很全面, 但无法找到元素 'context:component-scan' 的声明“的错误的更多相关文章
- 通配符的匹配很全面, 但无法找到元素 'context:property-placeholder' 的声明。
在Spring相应包导入正确的前提下,出现这个异常,是因为我们在引入命名空间的时候,没有正确引入它的DTD解析文件,以上面的context为例,解决办法如下: 在引入 xmlns:context=&q ...
- 通配符的匹配很全面, 但无法找到元素 'context:property-placeholder'
解决方案就是如下: xmlns:context="http://www.springframework.org/schema/context" 同时在xsi:schemaLocat ...
- 通配符的匹配很全面, 但无法找到元素 'context:component-scan' 的声明。
错误原因: xml文件中,本来是要配置成下面这样的: http://www.springframework.org/schema/context http://www.springframework. ...
- Spring:通配符的匹配很全面, 但无法找到元素 XXXXX' 的声明
问题:配置Spring的时候容易发生如题的这样一个经常性的错误,错误如下(以context为例) org.springframework.beans.factory.xml.XmlBeanDefini ...
- 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 ...
- 通配符的匹配很全面, 但无法找到元素 'cache:advice' 的声明
EB-INF\classes\spring-jdbc.xml] is invalid; nested exception is org.xml.sax.SAXParseException; lineN ...
- idea调试SpringMvc, 出现:”通配符的匹配很全面, 但无法找到元素 'mvc:annotation-driven' 的声明“错误的解决方法
调试json格式输出,出现以下错误: HTTP Status 500 - Servlet.init() for servlet HelloDispatcher threw exception ty ...
- 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 ...
- springMVC:通配符的匹配很全面, 但无法找到元素 'mvc:annotation-driven' 的声明
转自:http://blog.csdn.net/tolcf/article/details/50845483 报错信息:通配符的匹配很全面, 但无法找到元素 'mvc:annotation-drive ...
随机推荐
- 如何在B2C电子商务网站后台添加CNZZ统计代码(转)
CNZZ作为网站流量数据统计分析工具的一种,和百度统计工具类似,同样也是用于查看分析网站所有流量数据来源的一种站长工具,当然商家可根据自己的习惯在B2C电子商务网站后台添加相应的数据统计代码来管理您的 ...
- Java 数据类型及转换
整形: byte(1个字节) 范围:-128~127 short(2个字节) 范围:-215~215-1 (-32768~32767) int(4个字节) 范围:-231~231-1 (-214748 ...
- PAT1018——最短路加DFS
http://pat.zju.edu.cn/contests/pat-a-practise/1018 在杭州各个点,有很多自助自行车的点,最大容纳点为CMAX,但比较适合的情况是CMAX/2, 现在从 ...
- laravel 中条件查询 function模式
当需要条件查找时,可以使用下面的注入方法: //我要预约 yudoc_name yudoc_keshi yudoc_jibing yudoc_hospital 这是需要帅选的条件 public fun ...
- Linux:Linux 常用命令讲解(软件、硬件、文件)
一.Linux 常用命令 所有的命令操作都是在服务器上进行的 自学参考:菜鸟 Linux man + 命令:查看命令的文档: 命令 + --usage:查看命令的文档: 命令 + --help ...
- Android Intent Action 大全
1.Intent的用法: (1)Action跳转 1. 使用Action跳转,当程序AndroidManifest.xml中某一个 Activity的IntentFilter定义了包含Action,如 ...
- leetcode375
public class Solution { public int GetMoneyAmount(int n) { , n + ]; , n); } int DP(int[,] t, int s, ...
- linux进程的管道通信
linux进程的管道通信 要求 编程实现进程的管道通信,掌握管道通信的同步和互斥机制. 相关函数 pipe管道 指用于连接一个读进程和一个写进程以实现他们之间通信的一个共享文件,又名pipe文件.向管 ...
- 浅谈PL/SQL语言基础
在前面的学习中,我们大部分接触的都是SQL语言,但是,在实现复杂操作的时候,SQL语言就无能为力了,这时候就需要引入新的语言,PL/SQL语言就是对SQL语言的扩展,可以实现存储过程,函数等的创建.下 ...
- python子进程模块subprocess详解与应用实例 之二
1.2. Popen 对象 Popen类的实例有下列方法: 1. Popen.poll() 检查子进程是否已经结束,设置并返回返回码值. 2. Popen.wait() 等待子进程结束,设置并返回返回 ...