From b2e3be10d464615109f323d4dd4b651aa0e7b0d1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Nicoll?= Date: Mon, 27 Nov 2023 08:29:10 +0100 Subject: [PATCH] Add test to reproduce behavior See gh-24502 --- .../EnableTransactionManagementTests.java | 56 +++++++++++++++++++ 1 file changed, 56 insertions(+) diff --git a/spring-tx/src/test/java/org/springframework/transaction/annotation/EnableTransactionManagementTests.java b/spring-tx/src/test/java/org/springframework/transaction/annotation/EnableTransactionManagementTests.java index b9d70ee6a6..8cdad47580 100644 --- a/spring-tx/src/test/java/org/springframework/transaction/annotation/EnableTransactionManagementTests.java +++ b/spring-tx/src/test/java/org/springframework/transaction/annotation/EnableTransactionManagementTests.java @@ -20,6 +20,7 @@ import java.util.Collection; import java.util.Map; import java.util.Properties; +import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; import org.springframework.aop.support.AopUtils; @@ -288,6 +289,22 @@ public class EnableTransactionManagementTests { ctx.close(); } + @Test + @Disabled("gh-24502") + public void gh24502AppliesTransactionOnlyOnAnnotatedInterface() { + AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(Gh24502ConfigA.class); + Object bean = ctx.getBean("testBean"); + CallCountingTransactionManager txManager = ctx.getBean(CallCountingTransactionManager.class); + + ((TransactionalInterface)bean).methodOne(); + ((NonTransactionalInterface)bean).methodTwo(); + assertThat(txManager.begun).isEqualTo(1); + assertThat(txManager.commits).isEqualTo(1); + assertThat(txManager.rollbacks).isEqualTo(0); + + ctx.close(); + } + @Service public static class TransactionalTestBean { @@ -548,4 +565,43 @@ public class EnableTransactionManagementTests { } } + @Transactional + interface TransactionalInterface { + + void methodOne(); + + } + + interface NonTransactionalInterface { + + void methodTwo(); + } + + static class MixedTransactionalTestService implements TransactionalInterface, NonTransactionalInterface { + + @Override + public void methodOne() { + } + + @Override + public void methodTwo() { + } + } + + @Configuration + @EnableTransactionManagement(proxyTargetClass = false) + static class Gh24502ConfigA { + + @Bean + public MixedTransactionalTestService testBean() { + return new MixedTransactionalTestService(); + } + + @Bean + public PlatformTransactionManager txManager() { + return new CallCountingTransactionManager(); + } + + } + }