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

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/19224283/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-08 06:16:32  来源:igfitidea点击:

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

spring

提问by Ithar

I am using Spring 3.2.3.RELEASEwith maven to pull the dependencies. When building the project in Eclipse am getting following error:

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

My appication-context.xml has the following:

我的 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" />

I know that I am pulling the correct jar files as my Maven Dependencies shows:

我知道我正在提取正确的 jar 文件,因为我的 Maven 依赖项显示:

Eclipse Maven Dependencies

Eclipse Maven 依赖项

Inside the META-INF/sping.schemas I can see that I have the right schema declaration in my jar:

在 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

I have also looked at these to no avail:

我也看了这些无济于事:

Can't load spring 3 schemas

无法加载 spring 3 模式

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

匹配的通配符是严格的,但找不到元素 'tx:annotation-driven' 的声明

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

找不到元素“context:component-scan”的声明

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

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

Please help, it's driving me crazy .... :(

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

回答by M. Deinum

For starters you should fix your dependencies. You are mixing Spring 3.2.3 and 2.0.6 jars (that is problems waiting to happen).

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

Next to that your declaration is wrong http://www.springframework.org/schema/context/must be http://www.springframework.org/schema/context.

旁边说你的声明是错误的http://www.springframework.org/schema/context/一定是http://www.springframework.org/schema/context