没有声明可以找到元素的上下文:组件扫描' [英] No declaration can be found for element 'context:component-scan'

查看:86
本文介绍了没有声明可以找到元素的上下文:组件扫描'的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我从Spring 3(3.1.2)和Google App Engine开始。



我在网上跟着一个tutoria,现在,我有我的bean -realted xml在启动时出现问题。



这是代码

 <?xml version =1.0encoding =UTF-8?> 
< 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
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\">
< context:component-scan base-package =my.example>

其中所有java文件的根包是my.example。子包装也是模型和控制器的子包装。
now。



当我启动应用程序时,我收到以下错误消息:

  org.springframework.beans.factory.xml.XmlBeanDefinitionStoreException:来自ServletContext资源的XML文档中的第10行[/WEB-INF/spring-servlet.xml]无效;嵌套异常是org.xml.sax.SAXParseException:cvc-complex-type.2.4.c:匹配的通配符是严格的,但是对于元素'context:component-scan'没有声明。 

有很多堆栈跟踪。



有人知道我可以解决这个问题吗?
我检查了XSD,他们似乎是正确的。

解决方案

替换

  http://www.springframework.org/schema/context/spring-context.xsd 

by

  http://www.springframework.org/schema/context/spring-context-2.5.xsd 

这应该够了吧!我使用的是spring-context 3.1.1,我得到的错误指的是 http://www.springframework.org/schema/context/spring-context-2.1.xsd



然而,你也应该做一个maven树依赖性,并检查你是否有不同的春季版本。这个错误也可能是由于这个事实......


i'm starting with Spring 3 (3.1.2) and Google App Engine.

I've followed a tutoria online, now, i've my bean-realted xml which has a problem while starting.

this is the code

<?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:context="http://www.springframework.org/schema/context"
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">
<context:component-scan base-package="my.example">

where the root package of all the java file is "my.example". The subpackage are "model" and "controller" with subpackages as well. now.

when i start the app i receive back this error:

org.springframework.beans.factory.xml.XmlBeanDefinitionStoreException: Line 10 in XML document from ServletContext resource [/WEB-INF/spring-servlet.xml] is invalid; nested exception is org.xml.sax.SAXParseException: cvc-complex-type.2.4.c: The matching wildcard is strict, but no declaration can be found for element 'context:component-scan'.

with a lot of more stacktrace.

does anyone know how i can solve this? i checked the XSD and they seems to be correct.

解决方案

Problem is incompatible schema locations with your spring-context dependencies.

Replace

http://www.springframework.org/schema/context/spring-context.xsd

by

http://www.springframework.org/schema/context/spring-context-2.5.xsd

That should do the trick! I was using spring-context 3.1.1 and I was getting the same error referring to http://www.springframework.org/schema/context/spring-context-2.1.xsd

However, you should also do a maven tree dependendency and check if you've got different spring versions. This error could be due to this fact also...

这篇关于没有声明可以找到元素的上下文:组件扫描'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆