Java Reference
In-Depth Information
interval. You then create two steps that inherit from vehicleStep : carStep and truckStep . Each uses the
same reader and writer that has been configured in vehicleStep . In each case, they add an item
processor that does different things. carStep has chosen to use the inherited commit-interval of 50
items, whereas truckStep has overridden the commit-interval and set it to 5 items.
Listing 4-32. Adding Attributes in Step Inheritance
<step id="vehicleStep">
<tasklet>
<chunk reader="vehicleReader" writer="vehicleWriter" commit-interval="50"/>
</tasklet>
</step>
<step id="carStep" parent="vehicleStep">
<tasklet>
<chunk processor="carProcessor"/>
</tasklet>
</step>
<step id="truckStep" parent="vehicleStep">
<tasklet>
<chunk processor="truckProcessor" commit-interval="5"/>
</tasklet>
</step>
<job id="exampleJob">
<step id="step1" parent="carStep" next="step2"/>
<step id="step2" parent="truckStep"/>
</job>
By declaring a step abstract, as in Java, you're allowed to leave things out that would otherwise be
required. In an abstract step, as in Listing 4-33, you're allowed to leave off the reader , writer , processor ,
and tasklet attributes. This would normally cause an initialization error when Spring tried to build the
step; but because it's declared abstract, Spring knows that those will be populated by the steps that
inherit it.
Listing 4-33. An Abstract Step and Its Implementations
<beans:bean id="inputFile"
class="org.springframework.core.io.FileSystemResource" scope="step">
<beans:constructor-arg value="#{jobParameters[inputFile]}"/>
</beans:bean>
<beans:bean id="outputFile"
class="org.springframework.core.io.FileSystemResource" scope="step">
<beans:constructor-arg value="#{jobParameters[outputFile]}"/>
</beans:bean>
<beans:bean id="inputReader"
class="org.springframework.batch.item.file.FlatFileItemReader">
<beans:property name="resource" ref="inputFile"/>
<beans:property name="lineMapper">
 
Search WWH ::




Custom Search