Java Reference
In-Depth Information
Listing 9-5. Configuring the Format Job's Input
<beans:bean id="customerFile"
class="" scope="step">
<beans:constructor-arg value="#{jobParameters[customerFile]}"/>
<beans:bean id="customerFileReader"
<beans:property name="resource" ref="customerFile"/>
<beans:property name="lineMapper">
<beans:property name="lineTokenizer">
<beans:property name="names"
<beans:property name="delimiter" value=","/>
<beans:property name="fieldSetMapper">
<beans:bean class="org.springframework.batch.item.file.mapping.
<beans:property name="prototypeBeanName" value="customer"/>
<beans:bean id="customer" class="com.apress.springbatch.chapter9.Customer"
There shouldn't be a lot of surprises in the configuration in Listing 9-4. You begin by configuring
customerFile as a resource for the ItemReader to read from. Next is customerFileReader , which consists
of a FlatFileItemReader . customerFileReader references customerFile as well as a LineMapper
implementation to convert each record of the file into a Customer object. Because you're processing a
basic CSV file, you're able to use DelimitedLineTokenizer to parse each record and
BeanWrapperFieldSetMapper to take the resulting FieldSet and populate a customer instance. The final
piece of the input configuration is a reference to the Customer object that the ItemReader uses to create
new Customer objects.
For the output side of things, you need to configure the output file, FlatFileItemWriter , and a
LineAggregator . This example uses the
org.springframework.batch.itemfile.transform.FormatterLineAggregator provided by Spring Batch.
Listing 9-6 shows the configuration for the job's output.
Search WWH ::

Custom Search