Java 春天。“schemaLocation ...必须有偶数个URI”

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/21630363/
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-08-13 09:45:24  来源:igfitidea点击:

spring. "schemaLocation ... must have even number of URI's"

javaxmlspringspring-mvcxsd

提问by gstackoverflow

snippet from my xml file:

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

after execution I see following message:

执行后,我看到以下消息:

WARN [WrapperSimpleAppMain] [XmlBeanDefinitionReader] Ignored XML validation warning org.xml.sax.SAXParseException; lineNumber: 14; columnNumber: 80; SchemaLocation: schemaLocation value = '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' must have even number of URI's. at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.createSAXParseException(ErrorHandlerWrapper.java:198)

警告 [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)

How to solve this problem right?

如何正确解决这个问题?

采纳答案by Sotirios Delimanolis

You're schemaLocationvalue should be of the form

你的schemaLocation价值应该是这样的

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

You're missing

你不见了

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

before

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

It should therefore be

因此应该是

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

Note that I've changed the utilschema to version 3.1. Don't mix and match. Use all the same versions.

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

回答by Brajesh

SchemaLocation must be in the form of namespace-name schema-location [namespace-name schema-location]

SchemaLocation 必须采用 namespace-name schema-location [namespace-name schema-location] 的形式

like example

喜欢的例子

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

Here we are conveying to xml that, we are going to use my custom tag that is 'mytag' which is defined in http://www.brajesh.com/tagsDefname-space location. You can validate these tags from http://www.brajesh.com/tagsDef.xsdlocation for http://www.brajesh.com/tagsDef. Due to this reason, schema location must have even URLs.

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