BATCH-2397: fix parameters handling in MethodInvokingTaskletAdapter
When a tasklet is declared with xml using the shortcut version, the MethodInvokingTaskletAdapter that is created automatically does not address passing parameters expected by Tasklet#execute (which is incorrect since the documentation of the schema attribute "method" says the bean should define a method with the same signature). This commit fixes parameters passing when using the shortcut version. Resolves BATCH-2397
This commit is contained in:
committed by
Michael Minella
parent
0d9f4ce6f1
commit
79f3a67883
@@ -16,11 +16,18 @@
|
||||
p:proxyTargetClass="true" />
|
||||
|
||||
<job id="loopJob" xmlns="http://www.springframework.org/schema/batch">
|
||||
<step id="step1">
|
||||
<!-- this step tests the usage of MethodInvokingTaskletAdapter declared as a bean -->
|
||||
<step id="step1" next="step2">
|
||||
<tasklet ref="adapter">
|
||||
<transaction-attributes propagation="REQUIRED"/>
|
||||
</tasklet>
|
||||
</step>
|
||||
|
||||
<!-- this step tests the shortcut version that automatically wraps a bean
|
||||
in a MethodInvokingTaskletAdapter -->
|
||||
<step id="step2">
|
||||
<tasklet ref="task" method="doWork"/>
|
||||
</step>
|
||||
</job>
|
||||
|
||||
<bean id="adapter"
|
||||
@@ -41,4 +48,7 @@
|
||||
scope="step">
|
||||
<property name="value" value="#{jobParameters[value]}" />
|
||||
</bean>
|
||||
|
||||
<bean id="task" class="org.springframework.batch.sample.TaskletJobFunctionalTests$Task"/>
|
||||
|
||||
</beans>
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2006-2007 the original author or authors.
|
||||
* Copyright 2006-2018 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -23,6 +23,7 @@ import org.junit.runner.RunWith;
|
||||
import org.springframework.batch.core.BatchStatus;
|
||||
import org.springframework.batch.core.JobExecution;
|
||||
import org.springframework.batch.core.JobParametersBuilder;
|
||||
import org.springframework.batch.core.scope.context.ChunkContext;
|
||||
import org.springframework.batch.test.JobLauncherTestUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
@@ -41,6 +42,7 @@ public class TaskletJobFunctionalTests {
|
||||
JobExecution jobExecution = jobLauncherTestUtils.launchJob(new JobParametersBuilder().addString("value", "foo")
|
||||
.toJobParameters());
|
||||
assertEquals(BatchStatus.COMPLETED, jobExecution.getStatus());
|
||||
assertEquals("yes", jobExecution.getExecutionContext().getString("done"));
|
||||
}
|
||||
|
||||
public static class TestBean {
|
||||
@@ -57,5 +59,18 @@ public class TaskletJobFunctionalTests {
|
||||
assertEquals(3.14, doubleValue, 0.01);
|
||||
}
|
||||
}
|
||||
|
||||
public static class Task {
|
||||
|
||||
public boolean doWork(ChunkContext chunkContext) {
|
||||
chunkContext.
|
||||
getStepContext().
|
||||
getStepExecution().
|
||||
getJobExecution().
|
||||
getExecutionContext().put("done", "yes");
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user