Java Reference
In-Depth Information
Listing 9-5. Configuring the Format Job's Input
<beans:bean id="customerFile"
class="org.springframework.core.io.FileSystemResource" scope="step">
<beans:constructor-arg value="#{jobParameters[customerFile]}"/>
</beans:bean>
<beans:bean id="customerFileReader"
class="org.springframework.batch.item.file.FlatFileItemReader">
<beans:property name="resource" ref="customerFile"/>
<beans:property name="lineMapper">
<beans:bean
class="org.springframework.batch.item.file.mapping.DefaultLineMapper">
<beans:property name="lineTokenizer">
<beans:bean
class="org.springframework.batch.item.file.transform.
DelimitedLineTokenizer">
<beans:property name="names"
value="firstName,middleInitial,lastName,address,city,state,zip"/>
<beans:property name="delimiter" value=","/>
</beans:bean>
</beans:property>
<beans:property name="fieldSetMapper">
<beans:bean class="org.springframework.batch.item.file.mapping.
BeanWrapperFieldSetMapper">
<beans:property name="prototypeBeanName" value="customer"/>
</beans:bean>
</beans:property>
</beans:bean>
</beans:property>
</beans:bean>
<beans:bean id="customer" class="com.apress.springbatch.chapter9.Customer"
scope="prototype"/>
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