Merge branch '6.0.x'

# Conflicts:
#	spring-aop/src/main/java/org/springframework/aop/aspectj/AspectJPointcutAdvisor.java
#	spring-tx/src/test/java/org/springframework/transaction/annotation/AnnotationTransactionInterceptorTests.java
This commit is contained in:
Sam Brannen
2023-09-20 17:06:35 +02:00
43 changed files with 336 additions and 405 deletions

View File

@@ -42,7 +42,7 @@ import static org.assertj.core.api.Assertions.assertThatIllegalStateException;
* @author Juergen Hoeller
* @author Mark Paluch
*/
public class AnnotationTransactionInterceptorTests {
class AnnotationTransactionInterceptorTests {
private final CallCountingTransactionManager ptm = new CallCountingTransactionManager();
@@ -54,7 +54,7 @@ public class AnnotationTransactionInterceptorTests {
@Test
public void classLevelOnly() {
void classLevelOnly() {
ProxyFactory proxyFactory = new ProxyFactory();
proxyFactory.setTarget(new TestClassLevelOnly());
proxyFactory.addAdvice(this.ti);
@@ -74,7 +74,7 @@ public class AnnotationTransactionInterceptorTests {
}
@Test
public void withSingleMethodOverride() {
void withSingleMethodOverride() {
ProxyFactory proxyFactory = new ProxyFactory();
proxyFactory.setTarget(new TestWithSingleMethodOverride());
proxyFactory.addAdvice(this.ti);
@@ -94,7 +94,7 @@ public class AnnotationTransactionInterceptorTests {
}
@Test
public void withSingleMethodOverrideInverted() {
void withSingleMethodOverrideInverted() {
ProxyFactory proxyFactory = new ProxyFactory();
proxyFactory.setTarget(new TestWithSingleMethodOverrideInverted());
proxyFactory.addAdvice(this.ti);
@@ -114,7 +114,7 @@ public class AnnotationTransactionInterceptorTests {
}
@Test
public void withMultiMethodOverride() {
void withMultiMethodOverride() {
ProxyFactory proxyFactory = new ProxyFactory();
proxyFactory.setTarget(new TestWithMultiMethodOverride());
proxyFactory.addAdvice(this.ti);
@@ -134,7 +134,7 @@ public class AnnotationTransactionInterceptorTests {
}
@Test
public void withRollbackOnRuntimeException() {
void withRollbackOnRuntimeException() {
ProxyFactory proxyFactory = new ProxyFactory();
proxyFactory.setTarget(new TestWithExceptions());
proxyFactory.addAdvice(this.ti);
@@ -150,7 +150,7 @@ public class AnnotationTransactionInterceptorTests {
}
@Test
public void withCommitOnCheckedException() {
void withCommitOnCheckedException() {
ProxyFactory proxyFactory = new ProxyFactory();
proxyFactory.setTarget(new TestWithExceptions());
proxyFactory.addAdvice(this.ti);
@@ -162,7 +162,7 @@ public class AnnotationTransactionInterceptorTests {
}
@Test
public void withRollbackOnCheckedExceptionAndRollbackRule() {
void withRollbackOnCheckedExceptionAndRollbackRule() {
ProxyFactory proxyFactory = new ProxyFactory();
proxyFactory.setTarget(new TestWithExceptions());
proxyFactory.addAdvice(this.ti);
@@ -174,7 +174,7 @@ public class AnnotationTransactionInterceptorTests {
}
@Test
public void withMonoSuccess() {
void withMonoSuccess() {
ProxyFactory proxyFactory = new ProxyFactory();
proxyFactory.setTarget(new TestWithReactive());
proxyFactory.addAdvice(new TransactionInterceptor(rtm, this.source));
@@ -185,7 +185,7 @@ public class AnnotationTransactionInterceptorTests {
}
@Test
public void withMonoFailure() {
void withMonoFailure() {
ProxyFactory proxyFactory = new ProxyFactory();
proxyFactory.setTarget(new TestWithReactive());
proxyFactory.addAdvice(new TransactionInterceptor(rtm, this.source));
@@ -196,7 +196,7 @@ public class AnnotationTransactionInterceptorTests {
}
@Test
public void withMonoRollback() {
void withMonoRollback() {
ProxyFactory proxyFactory = new ProxyFactory();
proxyFactory.setTarget(new TestWithReactive());
proxyFactory.addAdvice(new TransactionInterceptor(rtm, this.source));
@@ -207,7 +207,7 @@ public class AnnotationTransactionInterceptorTests {
}
@Test
public void withFluxSuccess() {
void withFluxSuccess() {
ProxyFactory proxyFactory = new ProxyFactory();
proxyFactory.setTarget(new TestWithReactive());
proxyFactory.addAdvice(new TransactionInterceptor(rtm, this.source));
@@ -218,7 +218,7 @@ public class AnnotationTransactionInterceptorTests {
}
@Test
public void withFluxFailure() {
void withFluxFailure() {
ProxyFactory proxyFactory = new ProxyFactory();
proxyFactory.setTarget(new TestWithReactive());
proxyFactory.addAdvice(new TransactionInterceptor(rtm, this.source));
@@ -229,7 +229,7 @@ public class AnnotationTransactionInterceptorTests {
}
@Test
public void withFluxRollback() {
void withFluxRollback() {
ProxyFactory proxyFactory = new ProxyFactory();
proxyFactory.setTarget(new TestWithReactive());
proxyFactory.addAdvice(new TransactionInterceptor(rtm, this.source));
@@ -240,7 +240,7 @@ public class AnnotationTransactionInterceptorTests {
}
@Test
public void withCompletableFutureSuccess() {
void withCompletableFutureSuccess() {
ProxyFactory proxyFactory = new ProxyFactory();
proxyFactory.setTarget(new TestWithCompletableFuture());
proxyFactory.addAdvice(this.ti);
@@ -251,7 +251,7 @@ public class AnnotationTransactionInterceptorTests {
}
@Test
public void withCompletableFutureRuntimeException() {
void withCompletableFutureRuntimeException() {
ProxyFactory proxyFactory = new ProxyFactory();
proxyFactory.setTarget(new TestWithCompletableFuture());
proxyFactory.addAdvice(this.ti);
@@ -262,7 +262,7 @@ public class AnnotationTransactionInterceptorTests {
}
@Test
public void withCompletableFutureCheckedException() {
void withCompletableFutureCheckedException() {
ProxyFactory proxyFactory = new ProxyFactory();
proxyFactory.setTarget(new TestWithCompletableFuture());
proxyFactory.addAdvice(this.ti);
@@ -273,7 +273,7 @@ public class AnnotationTransactionInterceptorTests {
}
@Test
public void withCompletableFutureCheckedExceptionAndRollbackRule() {
void withCompletableFutureCheckedExceptionAndRollbackRule() {
ProxyFactory proxyFactory = new ProxyFactory();
proxyFactory.setTarget(new TestWithCompletableFuture());
proxyFactory.addAdvice(this.ti);
@@ -284,7 +284,7 @@ public class AnnotationTransactionInterceptorTests {
}
@Test
public void withVavrTrySuccess() {
void withVavrTrySuccess() {
ProxyFactory proxyFactory = new ProxyFactory();
proxyFactory.setTarget(new TestWithVavrTry());
proxyFactory.addAdvice(this.ti);
@@ -295,7 +295,7 @@ public class AnnotationTransactionInterceptorTests {
}
@Test
public void withVavrTryRuntimeException() {
void withVavrTryRuntimeException() {
ProxyFactory proxyFactory = new ProxyFactory();
proxyFactory.setTarget(new TestWithVavrTry());
proxyFactory.addAdvice(this.ti);
@@ -306,7 +306,7 @@ public class AnnotationTransactionInterceptorTests {
}
@Test
public void withVavrTryCheckedException() {
void withVavrTryCheckedException() {
ProxyFactory proxyFactory = new ProxyFactory();
proxyFactory.setTarget(new TestWithVavrTry());
proxyFactory.addAdvice(this.ti);
@@ -317,7 +317,7 @@ public class AnnotationTransactionInterceptorTests {
}
@Test
public void withVavrTryCheckedExceptionAndRollbackRule() {
void withVavrTryCheckedExceptionAndRollbackRule() {
ProxyFactory proxyFactory = new ProxyFactory();
proxyFactory.setTarget(new TestWithVavrTry());
proxyFactory.addAdvice(this.ti);
@@ -328,7 +328,7 @@ public class AnnotationTransactionInterceptorTests {
}
@Test
public void withInterface() {
void withInterface() {
ProxyFactory proxyFactory = new ProxyFactory();
proxyFactory.setTarget(new TestWithInterfaceImpl());
proxyFactory.addInterface(TestWithInterface.class);
@@ -352,7 +352,7 @@ public class AnnotationTransactionInterceptorTests {
}
@Test
public void crossClassInterfaceMethodLevelOnJdkProxy() {
void crossClassInterfaceMethodLevelOnJdkProxy() {
ProxyFactory proxyFactory = new ProxyFactory();
proxyFactory.setTarget(new SomeServiceImpl());
proxyFactory.addInterface(SomeService.class);
@@ -370,7 +370,7 @@ public class AnnotationTransactionInterceptorTests {
}
@Test
public void crossClassInterfaceOnJdkProxy() {
void crossClassInterfaceOnJdkProxy() {
ProxyFactory proxyFactory = new ProxyFactory();
proxyFactory.setTarget(new OtherServiceImpl());
proxyFactory.addInterface(OtherService.class);
@@ -382,7 +382,7 @@ public class AnnotationTransactionInterceptorTests {
}
@Test
public void withInterfaceOnTargetJdkProxy() {
void withInterfaceOnTargetJdkProxy() {
ProxyFactory targetFactory = new ProxyFactory();
targetFactory.setTarget(new TestWithInterfaceImpl());
targetFactory.addInterface(TestWithInterface.class);
@@ -410,7 +410,7 @@ public class AnnotationTransactionInterceptorTests {
}
@Test
public void withInterfaceOnTargetCglibProxy() {
void withInterfaceOnTargetCglibProxy() {
ProxyFactory targetFactory = new ProxyFactory();
targetFactory.setTarget(new TestWithInterfaceImpl());
targetFactory.setProxyTargetClass(true);
@@ -459,7 +459,7 @@ public class AnnotationTransactionInterceptorTests {
@Transactional
public static class TestClassLevelOnly {
static class TestClassLevelOnly {
public void doSomething() {
assertThat(TransactionSynchronizationManager.isActualTransactionActive()).isTrue();
@@ -474,7 +474,7 @@ public class AnnotationTransactionInterceptorTests {
@Transactional
public static class TestWithSingleMethodOverride {
static class TestWithSingleMethodOverride {
public void doSomething() {
assertThat(TransactionSynchronizationManager.isActualTransactionActive()).isTrue();
@@ -495,7 +495,7 @@ public class AnnotationTransactionInterceptorTests {
@Transactional(readOnly = true)
public static class TestWithSingleMethodOverrideInverted {
static class TestWithSingleMethodOverrideInverted {
@Transactional
public void doSomething() {
@@ -516,7 +516,7 @@ public class AnnotationTransactionInterceptorTests {
@Transactional
public static class TestWithMultiMethodOverride {
static class TestWithMultiMethodOverride {
@Transactional(readOnly = true)
public void doSomething() {
@@ -538,7 +538,7 @@ public class AnnotationTransactionInterceptorTests {
@Transactional
public static class TestWithExceptions {
static class TestWithExceptions {
public void doSomethingErroneous() {
assertThat(TransactionSynchronizationManager.isActualTransactionActive()).isTrue();
@@ -569,7 +569,7 @@ public class AnnotationTransactionInterceptorTests {
@Transactional
public static class TestWithReactive {
static class TestWithReactive {
public Mono<Void> monoSuccess() {
return Mono.delay(Duration.ofSeconds(10)).then();
@@ -620,7 +620,7 @@ public class AnnotationTransactionInterceptorTests {
@Transactional
public static class TestWithVavrTry {
static class TestWithVavrTry {
public Try<String> doSomething() {
assertThat(TransactionSynchronizationManager.isActualTransactionActive()).isTrue();
@@ -649,14 +649,14 @@ public class AnnotationTransactionInterceptorTests {
}
public interface BaseInterface {
interface BaseInterface {
void doSomething();
}
@Transactional
public interface TestWithInterface extends BaseInterface {
interface TestWithInterface extends BaseInterface {
@Transactional(readOnly = true)
void doSomethingElse();
@@ -668,7 +668,7 @@ public class AnnotationTransactionInterceptorTests {
}
public static class TestWithInterfaceImpl implements TestWithInterface {
static class TestWithInterfaceImpl implements TestWithInterface {
@Override
public void doSomething() {
@@ -684,7 +684,7 @@ public class AnnotationTransactionInterceptorTests {
}
public interface SomeService {
interface SomeService {
void foo();
@@ -696,7 +696,7 @@ public class AnnotationTransactionInterceptorTests {
}
public static class SomeServiceImpl implements SomeService {
static class SomeServiceImpl implements SomeService {
@Override
public void bar() {
@@ -714,14 +714,14 @@ public class AnnotationTransactionInterceptorTests {
}
public interface OtherService {
interface OtherService {
void foo();
}
@Transactional
public static class OtherServiceImpl implements OtherService {
static class OtherServiceImpl implements OtherService {
@Override
public void foo() {

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2022 the original author or authors.
* Copyright 2002-2023 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -69,6 +69,25 @@ public class EnableTransactionManagementTests {
ctx.close();
}
@Test // gh-31238
public void cglibProxyClassIsCachedAcrossApplicationContexts() {
ConfigurableApplicationContext ctx;
// Round #1
ctx = new AnnotationConfigApplicationContext(EnableTxConfig.class, TxManagerConfig.class);
TransactionalTestBean bean1 = ctx.getBean(TransactionalTestBean.class);
assertThat(AopUtils.isCglibProxy(bean1)).as("testBean #1 is not a CGLIB proxy").isTrue();
ctx.close();
// Round #2
ctx = new AnnotationConfigApplicationContext(EnableTxConfig.class, TxManagerConfig.class);
TransactionalTestBean bean2 = ctx.getBean(TransactionalTestBean.class);
assertThat(AopUtils.isCglibProxy(bean2)).as("testBean #2 is not a CGLIB proxy").isTrue();
ctx.close();
assertThat(bean1.getClass()).isSameAs(bean2.getClass());
}
@Test
public void transactionProxyIsCreatedWithEnableOnSuperclass() {
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(