Java Reference
In-Depth Information
resource
Resource
null
(required)
A prototype of the resources to
be created by
MultiResourceItemWriter
.
resourceSuffixCreator
ResourceSuffix
Creator
null
Optionally,
MultiResourceItemWriter
can
use this class to append a
suffix to the end of the file
names it creates.
saveState
Boolean
true
If
false
, the state of the
ItemWriter isn't maintained in
the JobRepository.
To see how this works, you extract customers from the database and create XML files containing 10
customers each. To make this work, you don't need to develop any new code (you created the XML). All
you need to do is wire everything up. Let's start working with this example by looking at the
configuration for the job.
Listing 9-62 shows the configuration for the ItemReader in this example. In this case, it's a simple
JdbcCursorItemReader
configured to select all customers. From there, you pass the customers you
receive from the database to the ItemWriter you configure next.
Listing 9-62.
The
multiResource
formatJob
's ItemReader
…
<beans:bean id="customerItemReader"
class="org.springframework.batch.item.database.JdbcCursorItemReader">
<beans:property name="dataSource" ref="dataSource"/>
<beans:property name="sql" value="select * from customer"/>
<beans:property name="rowMapper" ref="customerRowMapper"/>
</beans:bean>
<beans:bean id="customerRowMapper"
class="com.apress.springbatch.chapter9.CustomerRowMapper"/>
…
The configuration for this ItemWriter is in layers. First you configure the
StaxEventItemWriter
that
you use for the XML generation. With that configured you layer
MultiResourceItemWriter
on top to
generate multiple resources the
StaxEventItemWriter
writes to. Listing 9-63 shows the configuration of
the output half of the job as well as the step and job configuration.
Listing 9-63.
ItemWriters and Step and Job Configuration
...
<beans:bean id="outputFile"
class="org.springframework.core.io.FileSystemResource" scope="step">
<beans:constructor-arg value="#{jobParameters[outputFile]}"/>
</beans:bean>
<beans:bean id="xmlOutputWriter"