2013-10-07 95 views
6

我正在使用Spring 3.2.3.RELEASE用maven來拉取依賴關係。當建立在Eclipse項目我收到以下錯誤:匹配的通配符是嚴格的,但是對元素的上下文沒有聲明:component-scan'

Exception in thread "main" org.springframework.beans.factory.xml.XmlBeanDefinitionStoreException: Line 17 in XML document from class path resource [META-INF/spring/application-context.xml] is invalid; nested exception is org.xml.sax.SAXParseException; lineNumber: 17; columnNumber: 64; cvc-complex-type.2.4.c: The matching wildcard is strict, but no declaration can be found for element 'context:component-scan'. 

我器件的應用-context.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:context="http://www.springframework.org/schema/context" 
    xsi:schemaLocation=" 
    http://www.springframework.org/schema/beans 
    http://www.springframework.org/schema/beans/spring-beans-3.2.xsd 
    http://www.springframework.org/schema/context/ 
    http://www.springframework.org/schema/context/spring-context-3.2.xsd"> 

    <context:component-scan base-package="com.example" /> 

我知道我拉了正確的jar文件作爲我的Maven依賴節目:

Eclipse Maven Dependencies

的META-INF/sping.schemas我可以看到我有正確的架構聲明在我的罐內:

http\://www.springframework.org/schema/context/spring-context-2.5.xsd=org/springframework/context/config/spring-context-2.5.xsd 
http\://www.springframework.org/schema/context/spring-context-3.0.xsd=org/springframework/context/config/spring-context-3.0.xsd 
http\://www.springframework.org/schema/context/spring-context-3.1.xsd=org/springframework/context/config/spring-context-3.1.xsd 
http\://www.springframework.org/schema/context/spring-context-3.2.xsd=org/springframework/context/config/spring-context-3.2.xsd 
http\://www.springframework.org/schema/context/spring-context.xsd=org/springframework/context/config/spring-context-3.2.xsd 

我也看了這些都無濟於事:

Can't load spring 3 schemas

The matching wildcard is strict, but no declaration can be found for element 'tx:annotation-driven'

No declaration can be found for element 'context:component-scan'

The matching wildcard is strict, but no declaration can be found for element 'context:component-scan

請幫幫忙,它的駕駛我瘋了.. .. :(

回答

14

對於初學者,您應該修復您的依賴關係。你在混合使用Spring 3.2.3和2.0.6 jar(這是等待發生的問題)。

旁邊,你的聲明是錯的http://www.springframework.org/schema/context/必須是http://www.springframework.org/schema/context

+0

Ooo gosh thanks;甚至沒有看到;除去最後的「/」這個技巧......將繼續對這些依賴關係進行排序。 – Ithar

+0

相同的東西。我們必須在最後用'/'複製/粘貼相同的教程 –

相關問題