有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

Spring批处理上的java Multilne xml文件

我使用Spring Batch读取数据库并编写xml文件,但我找不到一些配置来生成多个xml行文件,我需要这样做:

<xmlRecord><name>RecordOne</name></xmlRecord>
<xmlRecord><name>RecordTwo</name></xmlRecord>

每条记录排成一行

但我只能这样创造:

<xmlRecord><name>RecordOne</name></xmlRecord><xmlRecord><name>RecordTwo</name></xmlRecord>

这就是我的配置:

<bean id="itemWriter" class="org.springframework.batch.item.xml.StaxEventItemWriter" scope="step">
    <property name="resource"
        value="file:/var/opt/result.tmp" />
    <property name="marshaller" ref="userUnmarshaller" />
    <property name="overwriteOutput" value="true" />
    <property name="RootTagName" value="!-- --"/>
</bean>

封送bean配置:

<bean id="userUnmarshaller" class="org.springframework.oxm.jaxb.Jaxb2Marshaller">
    <property name="classesToBeBound">
        <list>
            <value>my.jaxb.data.TCRMService</value>
        </list>         
    </property>
    <property name="marshallerProperties"> 
        <map>               
            <entry>
                <key><util:constant static-field="javax.xml.bind.helpers.AbstractMarshallerImpl.JAXB_SCHEMA_LOCATION"/></key>
                <value>http://www.ibm.com/mdm/schema MDMDomains.xsd</value>
            </entry>
        </map>    
    </property>
</bean>

有人能帮我或提供一些配置来解决我的问题吗


共 (1) 个答案

  1. # 1 楼答案

    使用以下解组器配置:-

    <bean id="userUnmarshaller" class="org.springframework.oxm.jaxb.Jaxb2Marshaller">
        <property name="classesToBeBound">
            <list> your_class </list>
        </property>
        <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>
    </bean>
    

    你也可以这样做,比如:

    <property name="marshallerProperties">
            <map>
                <entry key="jaxb.formatted.output">
                    <value type="boolean">true</value>
                </entry>
            </map>
        </property>