1

我有一个非常简单的 xsd,它定义了一个元素“缓存”

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<xsd:schema xmlns="http://mysite/schema/cache"
    xmlns:xsd="http://www.w3.org/2001/XMLSchema"
    targetNamespace="http://mysite/schema/cache">

    <xsd:complexType name="objectType" abstract="false">
        <xsd:attribute name="target" type="xsd:string">
        </xsd:attribute>
     </xsd:complexType>

    <xsd:complexType name="cacheType">
       <xsd:sequence>
           <xsd:element name="object" type="xsd:string" maxOccurs="unbounded" />
       </xsd:sequence>
  </xsd:complexType>

  <xsd:element name="cache" type="cacheType"></xsd:element>
</xsd:schema>

我有一个弹簧配置文件:

<?xml version="1.0" encoding="utf-8"?>
<objects xmlns="http://www.springframework.net"
     xmlns:cache="http://mysite/schema/cache"
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
     xsi:schemaLocation="http://mysite/schema/cache http://mysite/cache.xsd">

   <description>
   </description>

  <cache:cache>
    <cache:object target="site"/>
 </cache:cache>
</objects>

在通话期间

Spring.Objects.Factory.Xml.XmlObjectDefinitionReader.DoLoadObjectDefinitions at startup, I get the following error:
    [XmlSchemaValidationException: The 'http://mysite/schema/cache:cache' element is not declared.] 

这表明 spring 找不到我的架构,但 xsd 可用。

任何想法为什么这不起作用?

4

1 回答 1

1

您需要向 Spring 声明您的架构存在,请参阅架构创作的附录

特别是第 B.5 节。注册处理程序和模式。

Spring 使用两个文件来处理模式发现。

META-INF/spring.handlers 包含 XML Schema URI 到命名空间处理程序类的映射。

META-INF/spring.schemas 包含 XML 模式位置的映射(与 XML 文件中的模式声明一起引用,使用模式作为 'xsi:schemaLocation' 属性的一部分)到类路径资源。

于 2009-08-18T10:52:23.767 回答