Java Reference
In-Depth Information
Listing 4-25. Using MethodInvokingTaskletAdapter
<?xml version="1.0" encoding="UTF-8"?>
<beans:beans xmlns=" http://www.springframework.org/schema/batch"
xmlns:beans=" http://www.springframework.org/schema/beans"
xmlns:xsi=" http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation=" http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/batch
http://www.springframework.org/schema/batch/spring-batch-2.1.xsd">
<beans:import resource="../launch-context.xml"/>
<beans:bean id="service"
class="com.apress.springbatch.chapter4.ChapterFourService"/>
<beans:bean id="methodInvokingTaskletAdapter"
class="org.springframework.batch.core.step.tasklet.MethodInvokingTaskletAdapter">
<beans:property name="targetObject" ref="service"/>
<beans:property name="targetMethod" value="serviceMethod"/>
</beans:bean>
<job id="methodInvokingJob">
<step id="step1">
<tasklet ref="methodInvokingTaskletAdapter"/>
</step>
</job>
</beans:beans>
The example shown in Listing 4-25 specifies an object and a method. With this configuration, the
adapter calls the method with no parameters and returns an ExitStatus.COMPLETED result unless the
method specified also returns the type org.springframework.batch.core.ExitStatus . If it does return an
ExitStatus , the value returned by the method is returned from the tasklet. If you want to configure a
static set of parameters, you can use the late-binding method of passing job parameters that you read
about earlier in this chapter, as shown in Listing 4-26.
Listing 4-26. Using MethodInvokingTaskletAdapter with Parameters
<beans:bean id="methodInvokingTaskletAdapter"
class="org.springframework.batch.core.step.tasklet.MethodInvokingTaskletAdapter"
scope="step">
<beans:property name="targetObject" ref="service"/>
<beans:property name="targetMethod" value="serviceMethod"/>
<beans:property name="arguments" value="#{jobParameters[message]}"/>
</beans:bean>
<job id="methodInvokingJob">
<step id="step1">
<tasklet ref="methodInvokingTaskletAdapter"/>
</step>
</job>
 
Search WWH ::




Custom Search