有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java错误:spring dispatcher中命名空间上的“schemaLocation值***必须具有偶数个URI”

我犯了以下错误

<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.

我的DispatcherServlet具有以下名称空间

<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">  

我的错误消失了
这是怎么发生的,谁能告诉我


共 (2) 个答案

  1. # 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的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

  2. # 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定义的顺序不同,也会出现此警告