通配符匹配非常严格,但是找不到“context:component-scan”元素的声明。

6

我正在使用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'.

我的application-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中,我可以看到我在我的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

我也查看了以下内容,但没有发现任何解决方案: 无法加载Spring 3 schemas 'tx:annotation-driven'元素的匹配通配符很严格,但找不到声明 'context:component-scan'元素找不到声明 'context:component-scan'元素的匹配通配符很严格,但找不到声明 请帮忙解决问题,这真的把我逼疯了.... :(
1个回答

14

首先,您应该解决依赖关系。您正在混用Spring 3.2.3和2.0.6 JAR包(这是难以避免的问题)。

其次,您的声明有误,http://www.springframework.org/schema/context/ 应该是 http://www.springframework.org/schema/context


哦,谢谢;我甚至没有看到那个斜杠;去掉最后的“/”就解决了问题……我会开始解决那些依赖关系的。 - Ithar
同样的东西。我们一定是复制/粘贴了相同的教程,末尾带有 / - Nicolas Zozol

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接