diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/configuration/xml/CoreNamespacePostProcessor.java b/spring-batch-core/src/main/java/org/springframework/batch/core/configuration/xml/CoreNamespacePostProcessor.java index 2124d5f8d..5d25cd1f2 100644 --- a/spring-batch-core/src/main/java/org/springframework/batch/core/configuration/xml/CoreNamespacePostProcessor.java +++ b/spring-batch-core/src/main/java/org/springframework/batch/core/configuration/xml/CoreNamespacePostProcessor.java @@ -133,7 +133,7 @@ public class CoreNamespacePostProcessor implements BeanPostProcessor, BeanFactor fb.setJobRepository((JobRepository) applicationContext.getBean(DEFAULT_JOB_REPOSITORY_NAME)); } PlatformTransactionManager transactionManager = fb.getTransactionManager(); - if (transactionManager == null) { + if (transactionManager == null && fb.requiresTransactionManager()) { fb.setTransactionManager((PlatformTransactionManager) applicationContext .getBean(DEFAULT_TRANSACTION_MANAGER_NAME)); } diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/configuration/xml/StepParserStepFactoryBean.java b/spring-batch-core/src/main/java/org/springframework/batch/core/configuration/xml/StepParserStepFactoryBean.java index 9de89e0e2..0d3d654d6 100644 --- a/spring-batch-core/src/main/java/org/springframework/batch/core/configuration/xml/StepParserStepFactoryBean.java +++ b/spring-batch-core/src/main/java/org/springframework/batch/core/configuration/xml/StepParserStepFactoryBean.java @@ -241,6 +241,12 @@ class StepParserStepFactoryBean implements FactoryBean, BeanNameAware { } } + public boolean requiresTransactionManager() { + // Currently all step implementations other than TaskletStep are + // AbstractStep and do not require a transaction manager + return tasklet != null; + } + private void configureAbstractStep(AbstractStep ts) { if (name != null) { ts.setName(name); @@ -525,8 +531,8 @@ class StepParserStepFactoryBean implements FactoryBean, BeanNameAware { } private boolean isFaultTolerant() { - return backOffPolicy != null || skipPolicy != null || retryPolicy != null || isPositive(skipLimit) || isPositive(retryLimit) - || isPositive(cacheCapacity) || isTrue(readerTransactionalQueue); + return backOffPolicy != null || skipPolicy != null || retryPolicy != null || isPositive(skipLimit) + || isPositive(retryLimit) || isPositive(cacheCapacity) || isTrue(readerTransactionalQueue); } private boolean isTrue(Boolean b) { diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/xml/PartitionStepWithNonDefaultTransactionManagerParserTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/xml/PartitionStepWithNonDefaultTransactionManagerParserTests.java new file mode 100644 index 000000000..96e4ea709 --- /dev/null +++ b/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/xml/PartitionStepWithNonDefaultTransactionManagerParserTests.java @@ -0,0 +1,66 @@ +/* + * Copyright 2006-2007 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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.springframework.batch.core.configuration.xml; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; + +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.batch.core.BatchStatus; +import org.springframework.batch.core.Job; +import org.springframework.batch.core.JobExecution; +import org.springframework.batch.core.JobParameters; +import org.springframework.batch.core.repository.JobRepository; +import org.springframework.batch.core.repository.support.MapJobRepositoryFactoryBean; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; + + +/** + * @author Dave Syer + * + */ +@ContextConfiguration +@RunWith(SpringJUnit4ClassRunner.class) +public class PartitionStepWithNonDefaultTransactionManagerParserTests { + + @Autowired + private Job job; + + @Autowired + private JobRepository jobRepository; + + @Autowired + private MapJobRepositoryFactoryBean mapJobRepositoryFactoryBean; + + @Before + public void setUp() { + mapJobRepositoryFactoryBean.clear(); + } + + @Test + public void testDefaultHandlerStep() throws Exception { + assertNotNull(job); + JobExecution jobExecution = jobRepository.createJobExecution(job.getName(), new JobParameters()); + job.execute(jobExecution); + assertEquals(BatchStatus.COMPLETED, jobExecution.getStatus()); + } + + +} diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/step/item/FaultTolerantStepFactoryBeanTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/step/item/FaultTolerantStepFactoryBeanTests.java index b8089479d..2423186f9 100644 --- a/spring-batch-core/src/test/java/org/springframework/batch/core/step/item/FaultTolerantStepFactoryBeanTests.java +++ b/spring-batch-core/src/test/java/org/springframework/batch/core/step/item/FaultTolerantStepFactoryBeanTests.java @@ -957,7 +957,7 @@ public class FaultTolerantStepFactoryBeanTests { * expected: false; default classification */ @Test - public void testFatalSubset_unclassified() throws Exception { + public void testFatalSubsetUnclassified() throws Exception { assertFalse(getFatalSubsetSkipPolicy().shouldSkip(new RuntimeException(), 0)); } @@ -967,7 +967,7 @@ public class FaultTolerantStepFactoryBeanTests { * expected: true */ @Test - public void testFatalSubset_skippable() throws Exception { + public void testFatalSubsetSkippable() throws Exception { assertTrue(getFatalSubsetSkipPolicy().shouldSkip(new WriterNotOpenException(""), 0)); } @@ -977,7 +977,7 @@ public class FaultTolerantStepFactoryBeanTests { * expected: false */ @Test - public void testFatalSubset_fatal() throws Exception { + public void testFatalSubsetFatal() throws Exception { assertFalse(getFatalSubsetSkipPolicy().shouldSkip(new WriteFailedException(""), 0)); } diff --git a/spring-batch-core/src/test/resources/org/springframework/batch/core/configuration/xml/PartitionStepWithNonDefaultTransactionManagerParserTests-context.xml b/spring-batch-core/src/test/resources/org/springframework/batch/core/configuration/xml/PartitionStepWithNonDefaultTransactionManagerParserTests-context.xml new file mode 100644 index 000000000..1e477e470 --- /dev/null +++ b/spring-batch-core/src/test/resources/org/springframework/batch/core/configuration/xml/PartitionStepWithNonDefaultTransactionManagerParserTests-context.xml @@ -0,0 +1,32 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file