Java Reference
In-Depth Information
class="org.springframework.batch.item.xml.StaxEventItemWriter">
<beans:property name="marshaller" ref="customerMarshaller" />
<beans:property name="rootTagName" value="customers" />
</beans:bean>
<beans:bean id="customerMarshaller"
class="org.springframework.oxm.xstream.XStreamMarshaller">
<beans:property name="aliases">
<util:map>
<beans:entry key="customer"
value="com.apress.springbatch.chapter9.Customer" />
</util:map>
</beans:property>
</beans:bean>
<beans:bean id="multiResourceItemWriter"
class="org.springframework.batch.item.file.MultiResourceItemWriter">
<beans:property name="resource" ref="outputFile"/>
<beans:property name="delegate" ref="xmlOutputWriter"/>
<beans:property name="itemCountLimitPerResource" value="10"/>
</beans:bean>
<step id="formatFileStep">
<tasklet>
<chunk reader="customerItemReader" writer="multiResourceItemWriter"
commit-interval="10"/>
</tasklet>
</step>
<job id="formatJob">
<step id="step1" parent="formatFileStep"/>
</job>
As you saw earlier, the configuration of the output for this job begins with the outputFile
configuration. Although the file is generated by MultiResourceItemWriter , MultiResourceItemWriter uses
this as a template for each new file (file location and file name specifically). In the case, the outputFile
bean in Listing 9-63 serves as the template for the output file definition. With the file name configured,
you can configure xmlOutputWriter and customerMarshaller to generate the XML as required. Although
similar, it's important to note that xmlOutputWriter doesn't have a direct reference to the output file.
Instead, multiResourceItemWriter provides it when needed.
For this example, multiResourceItemWriter uses three dependencies: the resource you configured
previously, the xmlOutputWriter that does the actual work of writing to the files it creates, and the
number of customers that the ItemWriter writes per file ( itemCountLimitPerResource )—10 in this case.
The last piece for this job is configuring the step and job to put them to use. The configuration for the job
itself is straightforward, as Listing 9-63 shows. To use this job, you use the command listed in Listing 9-
64.
Listing 9-64. Command Used to Execute the multiResource Job
java -jar itemWriters-0.0.1-SNAPSHOT.jar jobs/multiResourceFormatJob.xml
formatJob outputFile=/output/custOutputs
 
Search WWH ::




Custom Search