我需要使用 Spring Batch 编写一个稍微复杂的 XML。任何人都可以帮助我进行适当的 Spring 配置吗?
以下是该过程所需的输出。
<XML>
<USERLIST ID="something" NAME="Sample">
<USER ID="userID" NAME="Name"/>
<USER ID="userID" NAME="Name"/>
........
</USERLIST>
<XML>
Run Code Online (Sandbox Code Playgroud)
上面 XML 中的“UserList”只需要出现一次
这是我到目前为止的弹簧配置。
<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>
Run Code Online (Sandbox Code Playgroud)
显然,当我对此进行测试时,我的 XML 中没有“USERLIST”元素,因为所有这些 USER 对象都需要添加到 USERLIST …