From 22952c30577443aa23f2f801a8569c25149cad15 Mon Sep 17 00:00:00 2001 From: Scott Frederick Date: Tue, 13 Feb 2024 15:37:32 -0600 Subject: [PATCH] Polish "Add BatchTransactionManager annotation" See gh-39473 --- .../batch/BatchTransactionManager.java | 7 ++--- .../batch/BatchAutoConfigurationTests.java | 30 +++++++++++++++++-- .../src/docs/asciidoc/howto/batch.adoc | 3 +- 3 files changed, 31 insertions(+), 9 deletions(-) diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/batch/BatchTransactionManager.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/batch/BatchTransactionManager.java index a2ec189a10..ee1360c541 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/batch/BatchTransactionManager.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/batch/BatchTransactionManager.java @@ -27,10 +27,9 @@ import org.springframework.context.annotation.Primary; import org.springframework.transaction.PlatformTransactionManager; /** - * Qualifier annotation for a {@link PlatformTransactionManager - * PlatformTransactionManager} to be injected into Batch auto-configuration. Can be used - * on a secondary {@link PlatformTransactionManager PlatformTransactionManager}, if there - * is another one marked as {@link Primary @Primary}. + * Qualifier annotation for a {@link PlatformTransactionManager} to be injected into Batch + * auto-configuration. Can be used on a secondary {@link PlatformTransactionManager}, if + * there is another one marked as {@link Primary @Primary}. * * @author Lasse Wulff * @since 3.3.0 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 0f55506d5e..d2a28accc7 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 @@ -80,13 +80,16 @@ import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Primary; import org.springframework.core.annotation.Order; import org.springframework.core.convert.support.ConfigurableConversionService; -import org.springframework.integration.transaction.PseudoTransactionManager; import org.springframework.jdbc.BadSqlGrammarException; import org.springframework.jdbc.core.JdbcTemplate; import org.springframework.jdbc.datasource.DataSourceTransactionManager; import org.springframework.jdbc.datasource.init.DatabasePopulator; import org.springframework.orm.jpa.JpaTransactionManager; import org.springframework.transaction.PlatformTransactionManager; +import org.springframework.transaction.TransactionDefinition; +import org.springframework.transaction.TransactionException; +import org.springframework.transaction.support.AbstractPlatformTransactionManager; +import org.springframework.transaction.support.DefaultTransactionStatus; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatExceptionOfType; @@ -544,13 +547,34 @@ class BatchAutoConfigurationTests { @Bean @Primary public PlatformTransactionManager normalTransactionManager() { - return new PseudoTransactionManager(); + return new TestTransactionManager(); } @BatchTransactionManager @Bean public PlatformTransactionManager batchTransactionManager() { - return new PseudoTransactionManager(); + return new TestTransactionManager(); + } + + } + + static class TestTransactionManager extends AbstractPlatformTransactionManager { + + @Override + protected Object doGetTransaction() throws TransactionException { + return null; + } + + @Override + protected void doBegin(Object transaction, TransactionDefinition definition) throws TransactionException { + } + + @Override + protected void doCommit(DefaultTransactionStatus status) throws TransactionException { + } + + @Override + protected void doRollback(DefaultTransactionStatus status) throws TransactionException { } } diff --git a/spring-boot-project/spring-boot-docs/src/docs/asciidoc/howto/batch.adoc b/spring-boot-project/spring-boot-docs/src/docs/asciidoc/howto/batch.adoc index 4bdf2930e2..ef4e8b90f7 100644 --- a/spring-boot-project/spring-boot-docs/src/docs/asciidoc/howto/batch.adoc +++ b/spring-boot-project/spring-boot-docs/src/docs/asciidoc/howto/batch.adoc @@ -21,8 +21,7 @@ For more info about Spring Batch, see the {spring-batch}[Spring Batch project pa [[howto.batch.specifying-a-transaction-manager]] === Specifying a Batch Transaction Manager -Similar to <> you can also define a `PlatformTransactionManager` -for use in the batch processing by marking it as `@BatchTransactionManager`. +Similar to <>, you can define a `PlatformTransactionManager` for use in the batch processing by marking it as `@BatchTransactionManager`. If you do so and want two transaction managers, remember to mark the other one as `@Primary`.