【问题标题】:org.xml.sax.SAXParseException ... no declaration can be found for element 'context:component-scan'org.xml.sax.SAXParseException ...找不到元素“上下文:组件扫描”的声明
【发布时间】:2013-07-17 14:27:19
【问题描述】:

我有一个 Eclipse-Maven-Spring 项目和一个applicationcontext.xml。这是:

        <?xml version="1.0" encoding="UTF-8"?>
    <beans xmlns="http://www.springframework.org/schema/beans"
      xmlns:security="http://www.springframework.org/schema/security"
      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.1.xsd
              http://www.springframework.org/schema/security/spring-security-3.1.xsd">

        <description>SoapClient1</description>

        <context:component-scan base-package="hu.bz.ikti.soap.test"/>
...
</beans>

解析xml时出现以下错误:

Exception in thread "main" org.springframework.beans.factory.xml.XmlBeanDefinitionStoreException: Line 19 in XML document from class path resource [META-INF/spring/app-context1.xml] is invalid; nested exception is org.xml.sax.SAXParseException: cvc-complex-type.2.4.c: The matching wildcard is strict, but no declaration can be found for element 'context:component-scan'.
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.doLoadBeanDefinitions(XmlBeanDefinitionReader.java:396)

在后面的&lt;http&gt; xml 元素的开头有一个错误标志:

    cvc-complex-type.2.4.a: Invalid content was found starting with element 'http'. One of '{"http://
 www.springframework.org/schema/beans":import, "http://www.springframework.org/schema/beans":alias, 
 "http://www.springframework.org/schema/beans":bean, WC[##other:"http://www.springframework.org/
 schema/beans"], "http://www.springframework.org/schema/beans":beans}' is expected.

xsi:schemaLocation 部分我尝试添加 http://www.springframework.org/schema/context/spring-context-3.2.xsd, spring-context-3.1.xsd, spring-context.xsd 但我总是遇到同样的错误。

我的pom.xml 中有以下内容:

    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-context</artifactId>
        <version>${spring.framework.version}</version>
    </dependency>

有人可以帮帮我吗?

【问题讨论】:

    标签: xml spring soap namespaces


    【解决方案1】:

    xsi:schemaLocation 不仅仅是一个架构列表,它是一个命名空间 URI 及其对应架构位置的 列表。所以你需要更多类似的东西

     xsi:schemaLocation="
              http://www.springframework.org/schema/beans
              http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
              http://www.springframework.org/schema/security
              http://www.springframework.org/schema/security/spring-security-3.1.xsd
              http://www.springframework.org/schema/context
              http://www.springframework.org/schema/context/spring-context-3.1.xsd">
    

    【讨论】:

    • 嗨,我已经添加了http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.1.xsd,但我仍然遇到同样的错误。
    • ...我已经有一个xmlns:context="http://www.springframework.org/schema/context" 元素。
    • @SzZ 你也修复了安全问题吗? schemaLocation 属性应该是交替命名空间和模式,您在问题中的示例是“beansNS beansSchema securitySchema”,即它缺少securityNS。你确定使用所有 Spring 库的 3.1 版吗?
    • 使用这些声明:&lt;beans xmlns="http://www.springframework.org/schema/beans" xmlns:security="http://www.springframework.org/schema/security" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security-3.1.xsd"&gt; 并添加 security: 前缀并将用户和密码标签放入问题已解决的工厂 bean。
    猜你喜欢
    • 2012-07-11
    • 2015-02-10
    • 2011-10-31
    • 2017-11-14
    • 1970-01-01
    • 2013-09-19
    • 2015-08-11
    • 2016-05-08
    • 1970-01-01
    相关资源
    最近更新 更多