diff --git a/execution/src/main/java/org/springframework/batch/execution/step/simple/SimpleStepExecutor.java b/execution/src/main/java/org/springframework/batch/execution/step/simple/SimpleStepExecutor.java
index db9c57d2e..7e2a279a0 100644
--- a/execution/src/main/java/org/springframework/batch/execution/step/simple/SimpleStepExecutor.java
+++ b/execution/src/main/java/org/springframework/batch/execution/step/simple/SimpleStepExecutor.java
@@ -40,6 +40,7 @@ import org.springframework.batch.repeat.RepeatCallback;
import org.springframework.batch.repeat.RepeatContext;
import org.springframework.batch.repeat.RepeatOperations;
import org.springframework.batch.repeat.exception.handler.ExceptionHandler;
+import org.springframework.batch.repeat.exception.handler.SimpleLimitExceptionHandler;
import org.springframework.batch.repeat.policy.SimpleCompletionPolicy;
import org.springframework.batch.repeat.support.RepeatTemplate;
import org.springframework.batch.repeat.synch.BatchTransactionSynchronizationManager;
@@ -157,7 +158,7 @@ public class SimpleStepExecutor implements StepExecutor {
final StepInstance step = stepExecution.getStep();
boolean isRestart = step.getStepExecutionCount() > 0 ? true : false;
Assert.notNull(step);
-
+
final Tasklet module = configuration.getTasklet();
ExitStatus status = ExitStatus.FAILED;
@@ -430,7 +431,9 @@ public class SimpleStepExecutor implements StepExecutor {
*
If the configuration is a {@link SimpleStepConfiguration} then we
* apply the commit interval at the chunk level and the exception handler at
* the step level, provided the existing repeat operations are instances of
- * {@link RepeatTemplate}.
+ * {@link RepeatTemplate}. In addition if there is a non-zero skip limit
+ * and no {@link ExceptionHandler} then we inject a
+ * {@link SimpleLimitExceptionHandler} with that limit.
*
*
* @param configuration
@@ -447,14 +450,13 @@ public class SimpleStepExecutor implements StepExecutor {
.state(chunkOperations != null,
"Chunk operations obtained from step configuration must be non-null.");
-
if (chunkOperations != null) {
setChunkOperations(chunkOperations);
}
if (stepOperations != null) {
setStepOperations(stepOperations);
}
-
+
} else if (configuration instanceof SimpleStepConfiguration) {
SimpleStepConfiguration simpleConfiguation = (SimpleStepConfiguration) configuration;
@@ -463,9 +465,19 @@ public class SimpleStepExecutor implements StepExecutor {
template.setCompletionPolicy(new SimpleCompletionPolicy(
simpleConfiguation.getCommitInterval()));
}
+
ExceptionHandler exceptionHandler = simpleConfiguation
.getExceptionHandler();
- if (this.stepOperations instanceof RepeatTemplate && exceptionHandler!=null) {
+
+ if (simpleConfiguation.getSkipLimit() > 0
+ && exceptionHandler == null) {
+ SimpleLimitExceptionHandler handler = new SimpleLimitExceptionHandler();
+ handler.setLimit(simpleConfiguation.getSkipLimit());
+ exceptionHandler = handler;
+ }
+
+ if (this.stepOperations instanceof RepeatTemplate
+ && exceptionHandler != null) {
RepeatTemplate template = (RepeatTemplate) this.stepOperations;
template.setExceptionHandler(exceptionHandler);
}
diff --git a/execution/src/test/java/org/springframework/batch/execution/step/simple/DefaultStepExecutorTests.java b/execution/src/test/java/org/springframework/batch/execution/step/simple/DefaultStepExecutorTests.java
index 9ae559c28..91681eb93 100644
--- a/execution/src/test/java/org/springframework/batch/execution/step/simple/DefaultStepExecutorTests.java
+++ b/execution/src/test/java/org/springframework/batch/execution/step/simple/DefaultStepExecutorTests.java
@@ -18,6 +18,7 @@ package org.springframework.batch.execution.step.simple;
import java.util.ArrayList;
import java.util.Arrays;
+import java.util.List;
import junit.framework.TestCase;
@@ -41,6 +42,8 @@ import org.springframework.batch.item.ItemProvider;
import org.springframework.batch.item.provider.ListItemProvider;
import org.springframework.batch.repeat.ExitStatus;
import org.springframework.batch.repeat.RepeatContext;
+import org.springframework.batch.repeat.exception.handler.DefaultExceptionHandler;
+import org.springframework.batch.repeat.exception.handler.ExceptionHandler;
import org.springframework.batch.repeat.interceptor.RepeatInterceptorAdapter;
import org.springframework.batch.repeat.policy.SimpleCompletionPolicy;
import org.springframework.batch.repeat.support.RepeatTemplate;
@@ -381,6 +384,45 @@ public class DefaultStepExecutorTests extends TestCase {
fail();
}
}
+
+ public void testApplyConfigurationWithExceptionHandler() throws Exception {
+ SimpleStepConfiguration stepConfiguration = new SimpleStepConfiguration("foo");
+ final List list = new ArrayList();
+ stepExecutor.setStepOperations(new RepeatTemplate() {
+ public void setExceptionHandler(ExceptionHandler exceptionHandler) {
+ list.add(exceptionHandler);
+ }
+ });
+ stepConfiguration.setExceptionHandler(new DefaultExceptionHandler());
+ stepExecutor.applyConfiguration(stepConfiguration);
+ assertEquals(1, list.size());
+ }
+
+ public void testApplyConfigurationWithZeroSkipLimit() throws Exception {
+ SimpleStepConfiguration stepConfiguration = new SimpleStepConfiguration("foo");
+ stepConfiguration.setSkipLimit(0);
+ final List list = new ArrayList();
+ stepExecutor.setStepOperations(new RepeatTemplate() {
+ public void setExceptionHandler(ExceptionHandler exceptionHandler) {
+ list.add(exceptionHandler);
+ }
+ });
+ stepExecutor.applyConfiguration(stepConfiguration);
+ assertEquals(0, list.size());
+ }
+
+ public void testApplyConfigurationWithNonZeroSkipLimit() throws Exception {
+ SimpleStepConfiguration stepConfiguration = new SimpleStepConfiguration("foo");
+ stepConfiguration.setSkipLimit(1);
+ final List list = new ArrayList();
+ stepExecutor.setStepOperations(new RepeatTemplate() {
+ public void setExceptionHandler(ExceptionHandler exceptionHandler) {
+ list.add(exceptionHandler);
+ }
+ });
+ stepExecutor.applyConfiguration(stepConfiguration);
+ assertEquals(1, list.size());
+ }
private class MockRestartableTasklet implements Tasklet, Restartable {
diff --git a/execution/src/test/java/org/springframework/batch/execution/step/simple/SimpleStepConfigurationTests.java b/execution/src/test/java/org/springframework/batch/execution/step/simple/SimpleStepConfigurationTests.java
index e1f867316..a96c8f556 100644
--- a/execution/src/test/java/org/springframework/batch/execution/step/simple/SimpleStepConfigurationTests.java
+++ b/execution/src/test/java/org/springframework/batch/execution/step/simple/SimpleStepConfigurationTests.java
@@ -70,6 +70,15 @@ public class SimpleStepConfigurationTests extends TestCase {
assertNotNull(configuration.getExceptionHandler());
}
+ /**
+ * Test method for {@link org.springframework.batch.execution.step.AbstractStepConfiguration#getExceptionHandler()}.
+ */
+ public void testSkipLimit() {
+ assertEquals(0, configuration.getSkipLimit());
+ configuration.setSkipLimit(2);
+ assertEquals(2, configuration.getSkipLimit());
+ }
+
/**
* Test method for {@link org.springframework.batch.execution.step.AbstractStepConfiguration#getSkipLimit()}.
*/