我正在使用Spring 3.2.3.RELEASE 和maven来提取依赖关系。在Eclipse中构建项目时出现以下错误:
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'.
我的appication-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 Dependencies显示:
在META-INF / sping.schemas中,我可以看到我的jar中有正确的模式声明:
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
我也看了这些无济于事:
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
请帮忙,这让我发疯了...... :(
答案 0 :(得分:14)
对于初学者,您应该修复您的依赖项。你正在混合Spring 3.2.3和2.0.6罐子(这是等待发生的问题)。
除此之外,您的声明错误http://www.springframework.org/schema/context/
必须为http://www.springframework.org/schema/context
。