0

Spring Batch ドキュメントによると、Spring Batch は書式設定された xml ファイルを生成できましたが、失敗しました。すべての XML 要素が 1 行で生成されます。

テスト手順

  1. spring-batch-2.1.9.RELEASE-no-dependencies をダウンロード
  2. spring-*-3.2.0.RC1.jar をインポート
  3. jaxb-ri-2.2.6 をインポート
  4. org.springframework.batch.sample.iosample.XmlFunctionalTests を実行する

ジョブを実行する前に、/spring-batch-2.1.9.RELEASE-no-dependencies/spring-batch-2.1.9.RELEASE/spring-batch-samples/src/main/resources/jobs/iosample に以下の変更を加えます。 /xml.xml

<bean id="itemWriter" class="org.springframework.batch.item.xml.StaxEventItemWriter">
    <property name="resource" ref="outputResource" />
    <property name="marshaller" ref="customerCreditMarshaller2" />
    <property name="rootTagName" value="customers" />
    <property name="overwriteOutput" value="true" />
</bean>
<bean id="customerCreditMarshaller2" class="org.springframework.oxm.jaxb.Jaxb2Marshaller">
     <property name="contextPaths">
         <list>
             <value>com.test.domain</value><!-- the package is generated from a XSD -->
         </list>
   </property>
   <property name="marshallerProperties">
        <map>
           <entry key="jaxb.formatted.output"><value type="java.lang.Boolean">true</value></entry>
        </map>
   </property>

4

2 に答える 2

1

JAXB API (com.sun.xml.bind.v2.runtime.output.IndentingUTF8XmlOutput) は、フォーマットされた XML をサポートします。

ただし、デフォルトでは、Spring Batch は com.sun.xml.bind.v2.runtime.output.IndentingUTF8XmlOutput を使用して出力 XML を生成しません。

そのため、Spring Batch が com.sun.xml.bind.v2.runtime.output.IndentingUTF8XmlOutput を使用してフォーマットされた XML を生成できるように、StreamResult を作成する必要があります。

于 2013-04-07T06:16:26.120 に答える
0

私はあなたがxmlを自分で読んでほしいと思っていると思います。春のバッチについてはわかりませんが、メモ帳 ++ を使用し、XML ツール プラグインをダウンロードしてから、「Pretty print (XML のみ - 改行あり)」を使用できます。理想的ではありませんが、すべてを 1 行で読むよりも読みやすくなります。

于 2013-04-03T15:05:26.303 に答える