Skip to content

Commit 22952c3

Browse files
Polish "Add BatchTransactionManager annotation"
See gh-39473
1 parent bb87faf commit 22952c3

File tree

3 files changed

+31
-9
lines changed

3 files changed

+31
-9
lines changed

spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/batch/BatchTransactionManager.java

+3-4
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,9 @@
2727
import org.springframework.transaction.PlatformTransactionManager;
2828

2929
/**
30-
* Qualifier annotation for a {@link PlatformTransactionManager
31-
* PlatformTransactionManager} to be injected into Batch auto-configuration. Can be used
32-
* on a secondary {@link PlatformTransactionManager PlatformTransactionManager}, if there
33-
* is another one marked as {@link Primary @Primary}.
30+
* Qualifier annotation for a {@link PlatformTransactionManager} to be injected into Batch
31+
* auto-configuration. Can be used on a secondary {@link PlatformTransactionManager}, if
32+
* there is another one marked as {@link Primary @Primary}.
3433
*
3534
* @author Lasse Wulff
3635
* @since 3.3.0

spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/batch/BatchAutoConfigurationTests.java

+27-3
Original file line numberDiff line numberDiff line change
@@ -80,13 +80,16 @@
8080
import org.springframework.context.annotation.Primary;
8181
import org.springframework.core.annotation.Order;
8282
import org.springframework.core.convert.support.ConfigurableConversionService;
83-
import org.springframework.integration.transaction.PseudoTransactionManager;
8483
import org.springframework.jdbc.BadSqlGrammarException;
8584
import org.springframework.jdbc.core.JdbcTemplate;
8685
import org.springframework.jdbc.datasource.DataSourceTransactionManager;
8786
import org.springframework.jdbc.datasource.init.DatabasePopulator;
8887
import org.springframework.orm.jpa.JpaTransactionManager;
8988
import org.springframework.transaction.PlatformTransactionManager;
89+
import org.springframework.transaction.TransactionDefinition;
90+
import org.springframework.transaction.TransactionException;
91+
import org.springframework.transaction.support.AbstractPlatformTransactionManager;
92+
import org.springframework.transaction.support.DefaultTransactionStatus;
9093

9194
import static org.assertj.core.api.Assertions.assertThat;
9295
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
@@ -544,13 +547,34 @@ public DataSource dataSource() {
544547
@Bean
545548
@Primary
546549
public PlatformTransactionManager normalTransactionManager() {
547-
return new PseudoTransactionManager();
550+
return new TestTransactionManager();
548551
}
549552

550553
@BatchTransactionManager
551554
@Bean
552555
public PlatformTransactionManager batchTransactionManager() {
553-
return new PseudoTransactionManager();
556+
return new TestTransactionManager();
557+
}
558+
559+
}
560+
561+
static class TestTransactionManager extends AbstractPlatformTransactionManager {
562+
563+
@Override
564+
protected Object doGetTransaction() throws TransactionException {
565+
return null;
566+
}
567+
568+
@Override
569+
protected void doBegin(Object transaction, TransactionDefinition definition) throws TransactionException {
570+
}
571+
572+
@Override
573+
protected void doCommit(DefaultTransactionStatus status) throws TransactionException {
574+
}
575+
576+
@Override
577+
protected void doRollback(DefaultTransactionStatus status) throws TransactionException {
554578
}
555579

556580
}

spring-boot-project/spring-boot-docs/src/docs/asciidoc/howto/batch.adoc

+1-2
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,7 @@ For more info about Spring Batch, see the {spring-batch}[Spring Batch project pa
2121

2222
[[howto.batch.specifying-a-transaction-manager]]
2323
=== Specifying a Batch Transaction Manager
24-
Similar to <<howto.batch.specifying-a-data-source>> you can also define a `PlatformTransactionManager`
25-
for use in the batch processing by marking it as `@BatchTransactionManager`.
24+
Similar to <<howto.batch.specifying-a-data-source>>, you can define a `PlatformTransactionManager` for use in the batch processing by marking it as `@BatchTransactionManager`.
2625
If you do so and want two transaction managers, remember to mark the other one as `@Primary`.
2726

2827

0 commit comments

Comments
 (0)