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

Posted

技术标签:

【中文标题】匹配的通配符是严格的,但找不到元素“context:component-scan”的声明【英文标题】:The matching wildcard is strict, but no declaration can be found for element 'context:component-scan' 【发布时间】:2013-10-07 11:56:28 【问题描述】:

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

我也看过这些无济于事:

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

请帮忙,这让我发疯了.... :(

【问题讨论】:

【参考方案1】:

对于初学者,您应该修复您的依赖项。您正在混合 Spring 3.2.3 和 2.0.6 罐子(这是等待发生的问题)。

旁边你的声明是错误的http://www.springframework.org/schema/context/必须是http://www.springframework.org/schema/context

【讨论】:

天哪,谢谢;甚至没有看到;删除最后的“/”就可以了......将继续整理这些依赖关系。 同样的东西。我们必须在末尾复制/粘贴与此 / 相同的教程

以上是关于匹配的通配符是严格的,但找不到元素“context:component-scan”的声明的主要内容,如果未能解决你的问题,请参考以下文章

匹配的通配符是严格的,但找不到元素 'oauth:authorization-server' 的声明

cvc-complex-type.2.4.c:匹配通配符是严格的,但找不到元素“mongo:mongo”的声明。 [11]

cvc-complex-type.2.4.c:匹配通配符是严格的,但找不到元素“mvc:annotation-driven”的声明

org.xml.sax.SAXParseException; cvc-complex-type.2.4.c:匹配的通配符是严格的,但找不到元素“mvc:resources”的声明

匹配的通配符是严格的,但是在servlet.xml中找不到多个元素的声明

解密:通配符的匹配很全面, 但无法找到元素 ‘context:annotation-config‘ 的声明