Java Reference
In-Depth Information
in an ordered list of properties to extract from the item along with the target object and method to be
called. The list you pass in in the same order as the parameters required for the property; Spring does
support dot notation (
address.city
, for example) as well as index properties (
e-mail[5]
). Just like the
ItemWriterAdapter
, this ItemWriter implementation also exposes an
arguments
property that isn't used
because the arguments are extracted by the writer dynamically. Listing 9-45 shows the job updated to
call the
logAddress
method instead of handling the entire
Customer
item.
Listing 9-45.
formatJob
Configured to Call the
logAddress
Method on
CustomerServiceImpl
...
<beans:bean id="parameterizedItemWriterAdapter"
class="org.springframework.batch.item.adapter.
PropertyExtractingDelegatingItemWriter">
<beans:property name="targetObject" ref="customerService"/>
<beans:property name="targetMethod" value="logAddress"/>
<beans:property name="fieldsUsedAsTargetMethodArguments"
value="address,city,state,zip"/>
</beans:bean>
<step id="formatFileStep">
<tasklet>
<chunk reader="customerFileReader"
writer="parameterizedItemWriterAdapter" commit-interval="10"/>
</tasklet>
</step>
<job id="formatJob">
<step id="step1" parent="formatFileStep"/>
</job>
…
When you run the job, the output of it consists of a sentence written to
System.out
with a formatted
address. Listing 9-46 shows a sample of the output you can expect.
Listing 9-46.
Output of
formatJob
Using
PropertyExtractingDelegatingItemWriter
2011-03-10 22:14:46,744 DEBUG main
[org.springframework.batch.repeat.support.RepeatTemplate] - <Repeat operation
about to start at count=9>
2011-03-10 22:14:46,744 DEBUG main
[org.springframework.batch.repeat.support.RepeatTemplate] - <Repeat operation
about to start at count=10>
2011-03-10 22:14:46,745 DEBUG main
[org.springframework.batch.repeat.support.RepeatTemplate] - <Repeat is
complete according to policy and result value.>
I just saved the address:
5570 Isabella Ave
St. Louis, IL
58540
I just saved the address:
4686 Mt. Lee Drive