diff --git a/spring-cloud-task-core/src/main/java/org/springframework/cloud/task/configuration/NoTransactionManagerProperty.java b/spring-cloud-task-core/src/main/java/org/springframework/cloud/task/configuration/NoTransactionManagerProperty.java index 9b49778f9..e94fa76b1 100644 --- a/spring-cloud-task-core/src/main/java/org/springframework/cloud/task/configuration/NoTransactionManagerProperty.java +++ b/spring-cloud-task-core/src/main/java/org/springframework/cloud/task/configuration/NoTransactionManagerProperty.java @@ -29,7 +29,7 @@ class NoTransactionManagerProperty extends NoneNestedConditions { NoTransactionManagerProperty() { - super(ConfigurationPhase.PARSE_CONFIGURATION); + super(ConfigurationPhase.REGISTER_BEAN); } @ConditionalOnProperty(prefix = "spring.cloud.task", name = "transaction-manager") diff --git a/spring-cloud-task-core/src/test/java/org/springframework/cloud/task/SimpleTaskAutoConfigurationTests.java b/spring-cloud-task-core/src/test/java/org/springframework/cloud/task/SimpleTaskAutoConfigurationTests.java index 73ea84954..ea39eb85d 100644 --- a/spring-cloud-task-core/src/test/java/org/springframework/cloud/task/SimpleTaskAutoConfigurationTests.java +++ b/spring-cloud-task-core/src/test/java/org/springframework/cloud/task/SimpleTaskAutoConfigurationTests.java @@ -23,6 +23,7 @@ import org.springframework.aop.framework.AopProxyUtils; import org.springframework.aop.scope.ScopedProxyUtils; +import org.springframework.batch.support.transaction.ResourcelessTransactionManager; import org.springframework.beans.factory.BeanCreationException; import org.springframework.beans.factory.NoSuchBeanDefinitionException; import org.springframework.beans.factory.annotation.Autowired; @@ -47,6 +48,7 @@ import org.springframework.context.ConfigurableApplicationContext; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; +import org.springframework.transaction.PlatformTransactionManager; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatExceptionOfType; @@ -173,6 +175,32 @@ public void testMultipleDataSources() { } + @Test + void testSpecifyTransactionManager() { + ApplicationContextRunner applicationContextRunner = new ApplicationContextRunner() + .withConfiguration(AutoConfigurations.of(PropertyPlaceholderAutoConfiguration.class, + SimpleTaskAutoConfiguration.class, SingleTaskConfiguration.class)) + .withBean("transactionManager", ResourcelessTransactionManager.class) + .withPropertyValues("spring.cloud.task.transaction-manager=transactionManager"); + applicationContextRunner.run((context) -> { + assertThat(context.getBeanNamesForType(PlatformTransactionManager.class)).hasSize(1) + .contains("transactionManager") + .doesNotContain("springCloudTaskTransactionManager"); + }); + } + + @Test + void testDefaultTransactionManager() { + ApplicationContextRunner applicationContextRunner = new ApplicationContextRunner() + .withConfiguration(AutoConfigurations.of(PropertyPlaceholderAutoConfiguration.class, + SimpleTaskAutoConfiguration.class, SingleTaskConfiguration.class)); + applicationContextRunner.run((context) -> { + assertThat(context.getBeanNamesForType(PlatformTransactionManager.class)).hasSize(1) + .contains("springCloudTaskTransactionManager") + .doesNotContain("transactionManager"); + }); + } + public void verifyExceptionThrownDefaultExecutable(Class classToCheck, ApplicationContextRunner applicationContextRunner) { Executable executable = () -> {