2013-07-17 40 views
0

我有一个Eclipse-Maven-Spring项目和一个applicationcontext.xml它。这就是:org.xml.sax.SAXParseException ...对于元素'context:component-scan'没有声明可以找到

 <?xml version="1.0" encoding="UTF-8"?> 
    <beans xmlns="http://www.springframework.org/schema/beans" 
     xmlns:security="http://www.springframework.org/schema/security" 
     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-3.1.xsd 
       http://www.springframework.org/schema/security/spring-security-3.1.xsd"> 

     <description>SoapClient1</description> 

     <context:component-scan base-package="hu.bz.ikti.soap.test"/> 
... 
</beans> 

当XML解析我得到以下错误:

Exception in thread "main" org.springframework.beans.factory.xml.XmlBeanDefinitionStoreException: Line 19 in XML document from class path resource [META-INF/spring/app-context1.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'. 
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.doLoadBeanDefinitions(XmlBeanDefinitionReader.java:396) 

有一个在后来的folloving <http> XML元素的开头一个错误信号:

cvc-complex-type.2.4.a: Invalid content was found starting with element 'http'. One of '{"http:// 
www.springframework.org/schema/beans":import, "http://www.springframework.org/schema/beans":alias, 
"http://www.springframework.org/schema/beans":bean, WC[##other:"http://www.springframework.org/ 
schema/beans"], "http://www.springframework.org/schema/beans":beans}' is expected. 

xsi:schemaLocation部分,我试图添加 http://www.springframework.org/schema/context/spring-context-3.2.xsd, spring-context-3.1.xsd, spring-context.xsd但所有的时候我得到了同样的错误。

我已在效法我pom.xml

<dependency> 
     <groupId>org.springframework</groupId> 
     <artifactId>spring-context</artifactId> 
     <version>${spring.framework.version}</version> 
    </dependency> 

有人能帮助我吗?

回答

2

xsi:schemaLocation不是简单的模式列表,它是名称空间URI及其相应模式位置的的列表。因此,你需要更多的东西一样

xsi:schemaLocation=" 
      http://www.springframework.org/schema/beans 
      http://www.springframework.org/schema/beans/spring-beans-3.1.xsd 
      http://www.springframework.org/schema/security 
      http://www.springframework.org/schema/security/spring-security-3.1.xsd 
      http://www.springframework.org/schema/context 
      http://www.springframework.org/schema/context/spring-context-3.1.xsd"> 
+0

嗨,我接着说:http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context- 3.1.xsd'但我仍然得到相同的错误。 – SzZ

+0

...我已经有一个'xmlns:context =“http://www.springframework.org/schema/context”'元素。 – SzZ

+0

@SzZ你是否也修复了安全问题? schemaLocation属性应该是交替命名空间和模式,你问题中的例子是“beansNS beansSchema securitySchema”,即它缺少安全性NS。你是否肯定使用所有弹簧库的3.1版本? –

相关问题