我正在使用 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 依赖项显示:
在 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
我也看过这些无济于事:
匹配的通配符是严格的,但找不到元素 'tx:annotation-driven' 的声明
匹配的通配符是严格的,但找不到元素 'context:component-scan 的声明
请帮忙,这让我发疯.... :(