Java Reference
In-Depth Information
Listing 10-48. Configuration of Writer Components for the Statement
<beans:bean id="statementFiles"
class="org.springframework.core.io.FileSystemResource">
<beans:constructor-arg value="/output/statement"/>
</beans:bean>
<beans:bean id="statementSuffixGenerator"
class="com.apress.springbatch.statement.writer.StatementSuffixGenerator"/>
<beans:bean id="statementFormatter"
class="com.apress.springbatch.statement.writer.StatementFormatter"/>
<beans:bean id="statementWriter"
class="org.springframework.batch.item.file.FlatFileItemWriter">
<beans:property name="headerCallback">
<beans:bean class="com.apress.springbatch.statement.writer.StatementHeaderCallback"/>
</beans:property>
<beans:property name="lineAggregator" ref="statementFormatter"/>
</beans:bean>
<beans:bean id="statementsWriter"
class="org.springframework.batch.item.file.MultiResourceItemWriter">
<beans:property name="resource" ref="statementFiles"/>
<beans:property name="resourceSuffixCreator" ref="statementSuffixGenerator"/>
<beans:property name="itemCountLimitPerResource" value="1"/>
<beans:property name="delegate" ref="statementWriter"/>
</beans:bean>
As Listing 10-48 shows, there is nothing extravagant for this step's writing. You begin by defining the
template resource on which the MultiResourceItemWriter bases each file. From there, you define the
configuration for statementSuffixGenerator , which appends a number.txt at the end of each file name.
StatementFormatter is configured next with no dependencies as required. Finally, you configure the two
ItemWriters involved.
FlatFileItemWriter uses two dependencies: a reference to the header callback and a reference to the
LineAggregator. This writer does the majority of the heavy lifting for your output. The final ItemWriter
involved in this step is MultiResourceItemWriter. It uses a reference to your resource to create similar
files, it uses the suffix generator to make the file names acceptable, and it delegates the writing of the
statement to the statementWriter you defined earlier. It's important to note that
itemCountLimitPerResource (the number of items per file you write) is set to 1 for this configuration.
Because StatementFormatter is designed to write an entire statement, you should write only one per file.
The code is written and configured. When you build and run the job, you're left with one file per
customer, with the customer's statement completed. Listing 10-49 shows an example of the statement as
it's generated.
Listing 10-49. A Sample Statement
Brokerage Account Statement
 
 
Search WWH ::




Custom Search