【问题标题】:Validate multiple schemas against a single Marshaller in spring在 spring 中针对单个 Marshaller 验证多个模式
【发布时间】:2016-11-23 05:24:11
【问题描述】:

在下面的场景中,我有一个编组器选择一个对象并针对 xsd 进行验证。我需要将此 Request 对象映射到一个编组器中的多个 xsd。

  <bean id="jaxbMarshallerForCOTRequestObject" class="org.springframework.oxm.jaxb.Jaxb2Marshaller">
        <property name="classesToBeBound">
            <list>
                <value>com.fidintl.retail.myProject.model.th.Request</value>
            </list>
        </property>
       <property name="schema" value="classpath:internal/test1.xsd"></property>
       <property name="validationEventHandler" ref="ceFeedXmlValidationEventHandlerService"></property>
        <property name="marshallerProperties">
            <map>
                <entry key="jaxb.encoding">
                    <value>ISO-8859-1</value>
                </entry>
            </map>
        </property>
    </bean>

有人可以提供方法吗? 我尝试使用&lt;schemas&gt; 标签,但它对我不起作用。

【问题讨论】:

    标签: java xml spring spring-integration


    【解决方案1】:

    我使用 Jaxb2Marshaller 的 setSchemas 方法在 java 而不是 xml 中完成了这项工作,它对我来说很好。

    Jaxb2Marshaller jaxb2Marshaller = new Jaxb2Marshaller();
    jaxb2Marshaller.setPackagesToScan(""); //mention packages here
    ClassPathResource xsdONE = new ClassPathResource(""); //path to first xsd
    ClassPathResource xsdTWO = new ClassPathResource(""); //path to second xsd
    jaxb2Marshaller.setSchemaLanguage(XMLConstants.W3C_XML_SCHEMA_NS_URI);
    jaxb2Marshaller.setSchemas(xsdONE, xsdTWO);
    jaxb2Marshaller.afterPropertiesSet();
    

    附: 我知道这是一篇旧帖子,但我前段时间一直在寻找答案,偶然发现了这篇文章。我在谷歌上搜索了一下然后尝试了一下之后找到了答案,所以认为它可能会帮助有人寻找答案。

    【讨论】:

      猜你喜欢
      • 2011-02-07
      • 2014-07-13
      • 1970-01-01
      • 1970-01-01
      • 2010-11-08
      • 2014-02-09
      • 2010-12-07
      • 1970-01-01
      • 2021-06-02
      相关资源
      最近更新 更多