【问题标题】:Error: "schemaLocation value *** must have even number of URI's." on namespaces in spring dispatcher错误:“schemaLocation 值 *** 必须有偶数个 URI。”在 Spring Dispatcher 中的命名空间上
【发布时间】:2013-05-15 19:17:48
【问题描述】:

我收到以下错误

<Ignored XML validation warning> org.xml.sax.SAXParseException; lineNumber: 9; columnNumber: 55;
SchemaLocation: schemaLocation value = 'http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
http://www.springframework.org/schema/tx' must have even number of URI's.

我的调度器 servlet 有以下命名空间

<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:p="http://www.springframework.org/schema/p"
       xmlns:aop="http://www.springframework.org/schema/aop"
       xmlns:tx="http://www.springframework.org/schema/tx"
       xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
       http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
       http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd">  

我把上面的都替换成了下面的

<beans xmlns="http://www.springframework.org/schema/beans"
              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-2.5.xsd">  

我的错误消失了。
这是怎么回事,谁能告诉我??

【问题讨论】:

    标签: java xml spring-mvc xsd


    【解决方案1】:

    schemaLocation 属性引用命名空间的 XML 架构文档。

    基本上在你输入时:

    xmlns:expns="http://www.example.com"
    xsi:schemaLocation="http://www.example.com
                        http://www.example.com/schema/example.xsd"
    

    你是说:"我将使用前缀 expns 作为命名空间的元素 http://www.example.com。还有,因此您可以验证这些元素,获取 http://www.example.com in http://www.example.com/schema/example.xsd"

    的 XSD 架构文件

    所以,换句话说,格式是:

    xsi:schemaLocation="namespace-a   where_to_get_the_xsd_for_namespace-a
                        namespace-b   where_to_get_the_xsd_for_namespace-b
                        namespace-c   where_to_get_the_xsd_for_namespace-c"
    

    等等。

    这就是为什么它必须是一个偶数


    更多信息和示例可以在here找到。

    【讨论】:

    • 那么你如何解决这个问题呢?您是否只是删除了格式不正确的xsi:schemaLocation,因为它当前实际上没有做任何事情?你知道命名空间应该是什么吗?如果有,怎么做?
    • @StephenOstermiller 您可以修复(添加对应项)xsi:schemaLocation 中导致其不均匀的条目,或者,如果您不知道对应项的正确值,请删除条目(因此无需删除整个 xsi:schemaLocation,尽管我猜这也可以)。
    【解决方案2】:

    @acdcjunior 解释正确,为了解决 OP 的问题,需要添加缺少的命名空间 p 的 schemaLocation

    <beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:p="http://www.springframework.org/schema/p"
       xmlns:aop="http://www.springframework.org/schema/aop"
       xmlns:tx="http://www.springframework.org/schema/tx"
       xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
    http://www.springframework.org/schema/p http://www.springframework.org/schema/xx-xx.xsd
       http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
       http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd">
    

    进一步说明,如果命名空间定义和 schemaLocation 定义的顺序不同,也会出现此警告

    【讨论】:

      猜你喜欢
      • 2014-03-05
      • 1970-01-01
      • 2017-04-08
      • 2015-02-21
      • 1970-01-01
      • 1970-01-01
      • 2019-10-18
      • 2019-02-21
      • 2015-11-15
      相关资源
      最近更新 更多