【问题标题】:spring. "schemaLocation ... must have even number of URI's"春天。 “schemaLocation ...必须有偶数个URI”
【发布时间】:2014-03-05 00:27:39
【问题描述】:

sn-p 来自我的 xml 文件:

<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:aop="http://www.springframework.org/schema/aop" 
       xmlns:util="http://www.springframework.org/schema/util"
       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/util 
           http://www.springframework.org/schema/util/spring-util.xsd
           http://www.springframework.org/schema/context/spring-context-3.1.xsd">

<!--            http://www.springframework.org/schema/aop  -->
<!--            http://www.springframework.org/schema/aop/spring-aop.xsd"> -->

    <context:component-scan base-package="myPackage" />

执行后我看到以下消息:

警告 [WrapperSimpleAppMain] [XmlBeanDefinitionReader] 忽略 XML 验证警告 org.xml.sax.SAXParseException;行号:14; 列号:80; SchemaLocation:schemaLocation 值 = 'http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
http://www.springframework.org/schema/util
http://www.springframework.org/schema/util/spring-util.xsd
http://www.springframework.org/schema/context/ spring-context-3.1.xsd' 必须有偶数个 URI。 在 com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.createSAXParseException(ErrorHandlerWrapper.java:198)

如何正确解决这个问题?

【问题讨论】:

    标签: java xml spring spring-mvc xsd


    【解决方案1】:

    您的schemaLocation 值应采用以下形式

    namespace-name schema-location [namespace-name schema-location]
    

    你不见了

    http://www.springframework.org/schema/context
    

    之前

    http://www.springframework.org/schema/context/spring-context-3.1.xsd
    

    因此应该是

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

    请注意,我已将 util 架构更改为 3.1 版。不要混搭。使用所有相同的版本。

    【讨论】:

    • @gstackoverflow 是的,你用xmlns:some-namespace-name 声明了一个命名空间。 schemaLocation 用于指向架构所在的位置,以便 XML 解析器可以验证文档中的 XML。
    • 我有 4 - xmlns:xsi xmlns:aop xmlns:util xmlns:context 在文件的开头和 3(beans util context) 在最后。正常吗?
    • @gstackoverflow 是的,这很正常。 xmlns:xsi 用于默认 XML 模式。例如,请参阅here
    • 那么一开始的aop呢?
    • @gstackoverflow 没注意到。理想情况下,您也应该有一个 schemaLocation 条目。
    【解决方案2】:

    SchemaLocation 必须采用以下形式 命名空间名称架构位置 [命名空间名称架构位置]

    喜欢的例子

    xmlns:mytag="http://www.brajesh.com/tagsDef"
    xsi:schemaLocation="http://www.brajesh.com/tagsDef
                        http://www.brajesh.com/tagsDef.xsd"
    

    在这里,我们向 xml 传达了这一点,我们将使用我的自定义标签,即在 http://www.brajesh.com/tagsDef 命名空间位置中定义的“mytag”。 您可以从http://www.brajesh.com/tagsDef.xsd 位置为http://www.brajesh.com/tagsDef 验证这些标签。 由于这个原因,架构位置必须具有偶数 URL。

    【讨论】:

      猜你喜欢
      • 2017-04-08
      • 1970-01-01
      • 2013-05-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-01-12
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多