JAXB绑定编译器将W3C XML模式转换为一个或多个java类,jaxb.properties
文件以及可能的一些资源文件。 JAXB还提供了一种从注释java类生成模式的方法。
Spring支持JAXB 2.0 API作为XML编组策略,遵循第21.2节“Marshaller和Unmarshaller”中描述的Marshaller
和Unmarshaller
接口。 相应的集成类驻留在org.springframework.oxm.jaxb包中。
21.5.1 Jaxb2Marshaller
Jaxb2Marshaller
类实现了SpringUnmarshaller
接口。 它需要一个上下文路径来操作,您可以使用contextpath
属性进行设置。 上下文路径是包含模式派生类的冒号(:)分离的Java包名称的列表。 它还提供了一个classesToBeBound
属性,它允许您设置要由编组器支持的类的数组。 通过向bean指定一个或多个模式资源来执行模式验证,如下所示:
<beans>
<bean id="jaxb2Marshaller" class="org.springframework.oxm.jaxb.Jaxb2Marshaller">
<property name="classesToBeBound">
<list>
<value>org.springframework.oxm.jaxb.Flight</value>
<value>org.springframework.oxm.jaxb.Flights</value>
</list>
</property>
<property name="schema" value="classpath:org/springframework/oxm/schema.xsd"/>
</bean>
...
</beans>
<oxm:jaxb2-marshaller id="marshaller" contextpath="org.springframework.ws.samples.airline.schema"/>
或者,可以通过待绑定的子标签将绑定的类列表提供给编组者:
"marshaller">
<oxm:class-to-be-bound name="org.springframework.ws.samples.airline.schema.Airport"/>
<oxm:class-to-be-bound name="org.springframework.ws.samples.airline.schema.Flight"/>
...
</oxm:jaxb2-marshaller>
<oxm:class-to-be-bound name="org.springframework.ws.samples.airline.schema.Airport"/>
<oxm:class-to-be-bound name="org.springframework.ws.samples.airline.schema.Flight"/>
...
</oxm:jaxb2-marshaller>
可用属性有:
Attribute | Description | required |
---|---|---|
id |
the id of the marshaller | no |
contextpath | the JAXB Context path | no |
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。