Spring Jaxb2Marshaller 外部绑定文件

Spring Jaxb2Marshaller External Binding File

在 Spring 中,我正在声明我的 org.springframework.oxm.jaxb.Jaxb2Marshaller,但我还想声明一个外部绑定文件:

<bean id="myMarshaller" class="org.springframework.oxm.jaxb.Jaxb2Marshaller">
    <property name="contextPath" value="com.path.to.pojos" />
    <property name="jaxbContextProperties">
        <util:map>
            <entry key="eclipselink.oxm.metadata-source">
                <list>
                    <value>com/path/to/schema/binding.xjb</value>
                </list>
            </entry>
        </util:map>
    </property>
    <property name="schema" value="classpath:com/path/to/schema/myService.xsd"/>
</bean>

我的绑定文件如下所示:

<jaxb:bindings version="1.0" 
    jaxb:version="2.0"
    xmlns:jaxb="http://java.sun.com/xml/ns/jaxb"
    xmlns:annox="http://annox.dev.java.net" 
    xmlns:xs="http://www.w3.org/2001/XMLSchema"
    xmlns:xjc="http://java.sun.com/xml/ns/jaxb/xjc"
    jaxb:extensionBindingPrefixes="xjc annox">

    <jaxb:bindings schemaLocation="myService.xsd" node="/xs:schema">

        <jaxb:globalBindings>
            <xjc:javaType name="java.util.Date" xmlType="xs:date"
            adapter="com.some.path.to.custom.adapter.DateAdapter" />
        </jaxb:globalBindings>

        <!-- More Declarations -->

        </jaxb:bindings>
    </jaxb:bindings>

此设置与 XJC 配合使用可以很好地从模式中生成对象以及外部绑定文件。但是我无法为我的 Spring 配置获得适当的设置。

我收到以下错误:

org.xml.sax.SAXParseException; lineNumber: 9; columnNumber: 77; unexpected     element (uri:"http://java.sun.com/xml/ns/jaxb", local:"bindings"). Expected elements are <{http://www.eclipse.org/eclipselink/xsds/persistence/oxm}xml-schema>,<{http://www.eclipse.org/eclipselink/xsds/persistence/oxm}xml-schema-type>,<{http://www.eclipse.org/eclipselink/xsds/persistence/oxm}xml-schema-types>,<{http://www.eclipse.org/eclipselink/xsds/persistence/oxm}xml-java-type-adapters>,<{http://www.eclipse.org/eclipselink/xsds/persistence/oxm}xml-registries>,<{http://www.eclipse.org/eclipselink/xsds/persistence/oxm}xml-enums>,<{http://www.eclipse.org/eclipselink/xsds/persistence/oxm}java-types>

我坚持这一点,我真的需要绑定文件与我的模式分开。我无法在网上找到此设置的任何示例,我想要一个关于如何使用 JaxB2Marshaller 正确配置外部绑定文件的示例。

如果我的问题不完整或需要更多信息,请告诉我。

谢谢,

日本

据我所知,绑定文件仅在编译时使用,用于从 XML 模式派生 Java 类。所以在运行时在编组器上配置它没有意义。 Spring 和 JAXB 都不会考虑它。您可以使用绑定文件配置的所有内容都已经在您的 com.path.to.pojos.* 类.