Java Reference
In-Depth Information
<beans:property name="names"
<beans:property name="delimiter" value=","/>
<beans:bean id="customerFieldSetMapper"
<beans:property name="prototypeBeanName" value="customer"/>
<beans:bean id="transactionFieldSetMapper"
<beans:bean id="customer" class="com.apress.springbatch.chapter7.Customer"
The configuration in Listing 7-27 should look familiar. It's essentially the exact same as the
configuration you used for multiple record formats (see Listing 7-19). The only addition, as highlighted
in bold, is the configuration of your new CustomerFileReader with its reference to the old ItemReader
and renaming the old ItemReader.
With the updated object model, the previous method for writing to your output file won't work for
this example. Because of this, I chose to use Spring Batch's PassThroughLineAggregator to write the
output for this example. It calls the item's toString() method and writes the output to the output file.
Listing 7-28 shows the updated ItemWriter configuration.
Listing 7-28. Updated outputWriter Configuration
<beans:bean id="outputFile"
class="" scope="step">
<beans:constructor-arg value="#{jobParameters[outputFile]}"/>
<beans:bean id="outputWriter"
<beans:property name="resource" ref="outputFile" />
<beans:property name="lineAggregator">
<beans:bean class="org.springframework.batch.item.file.transform.
For each Customer object, it will print how many transactions the user has. This will provide enough
detail for you to verify that your reading worked correctly. With the PassThroughLineAggregator
configured as it is, you only need to override the Customer's toString() method to format the output.
Listing 7-29 shows the updated method.
Listing 7-29. Customer's toString() Method
Search WWH ::

Custom Search