Java Reference
In-Depth Information
<beans:property name="marshaller" ref="customerMarshaller" />
<beans:property name="rootTagName" value="customers" />
<beans:bean id="customerMarshaller"
<beans:property name="aliases">
<beans:entry key="customer"
value="com.apress.springbatch.chapter9.Customer" />
<beans:bean id="multiResourceItemWriter"
<beans:property name="resource" ref="outputFile"/>
<beans:property name="delegate" ref="xmlOutputWriter"/>
<beans:property name="itemCountLimitPerResource" value="10"/>
<step id="formatFileStep">
<chunk reader="customerItemReader" writer="multiResourceItemWriter"
<job id="formatJob">
<step id="step1" parent="formatFileStep"/>
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-
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