1

Spring 4 O/X は、その抽象化の背後でいくつかの XML アンマーシャラーをサポートしています。JAXB2 を使用します。

Spring は受信 XML をスキーマに対して検証できますか? 公式ドキュメントにも、構成を説明する spring-oxmスキーマにも何も見つかりませんでした。これは私の現在の構成であり、かなり標準的です。

<bean id="jaxb2Marshaller" class="org.springframework.oxm.jaxb.Jaxb2Marshaller">
    <property name="marshallerProperties">
        <map>
            <!-- properties here -->
        </map>
    </property>
    <property name="classesToBeBound">
        <list>
            <value>com.example.Message1</value>
            <value>com.example.Message2</value>
        </list>
    </property>
</bean>
4

1 に答える 1

3

「Spring は受信 XML をスキーマに対して検証できますか?」

schemaプロパティを設定した場合:

public class Jaxb2Marshaller ... {
    /**
     * Set the schema resource to use for validation.
     */
    public void setSchema(Resource schemaResource) {
        this.schemaResources = new Resource[] {schemaResource};
    }

    /**
     * Set the schema resources to use for validation.
     */
    public void setSchemas(Resource... schemaResources) {
        this.schemaResources = schemaResources;
    }
}

これらのJaxb2Marshallerスキーマを使用して検証します。したがって、コンテキストxmlでは、次のようなことができます

<bean id="jaxb2Marshaller"
    class="org.springframework.oxm.jaxb.Jaxb2Marshaller">
    <property name="schema" value="classpath:myschema.xsd"/> 
    <property name="classesToBeBound">
        <list>
            <value>com.example.Message1</value>
            <value>com.example.Message2</value>
        </list>
    </property>
</bean> 
于 2014-09-17T20:26:40.223 に答える