【发布时间】:2014-08-04 23:44:36
【问题描述】:
我需要使用 Spring Batch 编写一个稍微复杂的 XML。任何人都可以帮助我进行适当的 Spring 配置吗?
以下是该过程所需的输出。
<XML>
<USERLIST ID="something" NAME="Sample">
<USER ID="userID" NAME="Name"/>
<USER ID="userID" NAME="Name"/>
........
</USERLIST>
<XML>
上面XML中的'UserList'只需要出现一次
这是我目前的spring配置。
<bean id="userXMLWriter" class="org.springframework.batch.item.xml.StaxEventItemWriter">
<property name="resource" value="file:outputs/users.xml" />
<property name="encoding" value="ISO-8859-1" />
<property name="version" value="1.0" />
<property name="marshaller" ref="userXMLMarshaller" />
<property name="rootTagName" value="XML" />
</bean>
<bean id="userXMLMarshaller" class="org.springframework.oxm.jaxb.Jaxb2Marshaller">
<property name="marshallerProperties">
<map>
<entry>
<key>
<util:constant static-field="javax.xml.bind.Marshaller.JAXB_FORMATTED_OUTPUT" />
</key>
<value type="java.lang.Boolean">true</value>
</entry>
</map>
</property>
<property name="classesToBeBound">
<list>
<value>org.test.model.xml.UserList</value>
<value>org.test.model.xml.User</value>
</list>
</property>
</bean>
显然,当我对此进行测试时,我的 XML 中没有“USERLIST”元素,因为所有这些 USER 对象都需要添加到某个地方的 USERLIST 中。我对 Spring Batch 和 JAXB2 有点陌生。对此的任何想法表示赞赏。
谢谢, 哈里什
【问题讨论】:
-
这个标签
是强制性的吗? -
是的,不幸的是:(
-
卢卡,我看过你提到的链接。这个要求与那个有些不同,但我从那篇文章中学到了一些东西。感谢分享链接!
-
为什么不使用用户列表元素的页眉/页脚回调?
标签: spring spring-batch jaxb2