diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/batch/BasicBatchConfigurer.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/batch/BasicBatchConfigurer.java index 960ddef77f..8c35a248f1 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/batch/BasicBatchConfigurer.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/batch/BasicBatchConfigurer.java @@ -47,10 +47,10 @@ public class BasicBatchConfigurer implements BatchConfigurer, InitializingBean { private final DataSource dataSource; - private PlatformTransactionManager transactionManager; - private final TransactionManagerCustomizers transactionManagerCustomizers; + private PlatformTransactionManager transactionManager; + private JobRepository jobRepository; private JobLauncher jobLauncher; @@ -76,11 +76,6 @@ public class BasicBatchConfigurer implements BatchConfigurer, InitializingBean { return this.jobRepository; } - @Override - public PlatformTransactionManager getTransactionManager() { - return this.transactionManager; - } - @Override public JobLauncher getJobLauncher() { return this.jobLauncher; @@ -98,7 +93,6 @@ public class BasicBatchConfigurer implements BatchConfigurer, InitializingBean { public void initialize() { try { - this.transactionManager = buildTransactionManager(); this.jobRepository = createJobRepository(); this.jobLauncher = createJobLauncher(); this.jobExplorer = createJobExplorer(); @@ -130,7 +124,7 @@ public class BasicBatchConfigurer implements BatchConfigurer, InitializingBean { map.from(this.dataSource).to(factory::setDataSource); map.from(this::determineIsolationLevel).whenNonNull().to(factory::setIsolationLevelForCreate); map.from(this.properties.getJdbc()::getTablePrefix).whenHasText().to(factory::setTablePrefix); - map.from(this::getTransactionManager).to(factory::setTransactionManager); + map.from(this::buildTransactionManager).to(factory::setTransactionManager); factory.afterPropertiesSet(); return factory.getObject(); } @@ -153,7 +147,12 @@ public class BasicBatchConfigurer implements BatchConfigurer, InitializingBean { if (this.transactionManagerCustomizers != null) { this.transactionManagerCustomizers.customize(transactionManager); } + this.transactionManager = transactionManager; return transactionManager; } + PlatformTransactionManager getTransactionManager() { + return this.transactionManager; + } + } diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/batch/BatchAutoConfigurationTests.java b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/batch/BatchAutoConfigurationTests.java index bf3f6ad5cd..b248d5cd7d 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/batch/BatchAutoConfigurationTests.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/batch/BatchAutoConfigurationTests.java @@ -309,7 +309,7 @@ class BatchAutoConfigurationTests { .run((context) -> { assertThat(context).hasSingleBean(BatchConfigurer.class); JpaTransactionManager transactionManager = JpaTransactionManager.class - .cast(context.getBean(BatchConfigurer.class).getTransactionManager()); + .cast(context.getBean(BasicBatchConfigurer.class).getTransactionManager()); assertThat(transactionManager.getDefaultTimeout()).isEqualTo(30); assertThat(transactionManager.isRollbackOnCommitFailure()).isTrue(); }); @@ -323,7 +323,7 @@ class BatchAutoConfigurationTests { .run((context) -> { assertThat(context).hasSingleBean(BatchConfigurer.class); DataSourceTransactionManager transactionManager = DataSourceTransactionManager.class - .cast(context.getBean(BatchConfigurer.class).getTransactionManager()); + .cast(context.getBean(BasicBatchConfigurer.class).getTransactionManager()); assertThat(transactionManager.getDefaultTimeout()).isEqualTo(30); assertThat(transactionManager.isRollbackOnCommitFailure()).isTrue(); }); @@ -336,7 +336,7 @@ class BatchAutoConfigurationTests { assertThat(context).hasSingleBean(BatchConfigurer.class) .hasSingleBean(BatchDataSourceScriptDatabaseInitializer.class).hasBean("batchDataSource"); DataSource batchDataSource = context.getBean("batchDataSource", DataSource.class); - assertThat(context.getBean(BatchConfigurer.class)).hasFieldOrPropertyWithValue("dataSource", + assertThat(context.getBean(BasicBatchConfigurer.class)).hasFieldOrPropertyWithValue("dataSource", batchDataSource); assertThat(context.getBean(BatchDataSourceScriptDatabaseInitializer.class)) .hasFieldOrPropertyWithValue("dataSource", batchDataSource);