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

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2019 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.
@@ -17,18 +17,23 @@
package org.springframework.aop;
/**
* Filter that restricts matching of a pointcut or introduction to
* a given set of target classes.
* Filter that restricts matching of a pointcut or introduction to a given set
* of target classes.
*
* <p>Can be used as part of a {@link Pointcut} or for the entire
* targeting of an {@link IntroductionAdvisor}.
* <p>Can be used as part of a {@link Pointcut} or for the entire targeting of
* an {@link IntroductionAdvisor}.
*
* <p>Concrete implementations of this interface typically should provide proper
* implementations of {@link Object#equals(Object)} and {@link Object#hashCode()}
* in order to allow the filter to be used in caching scenarios &mdash; for
* example, in proxies generated by CGLIB.
* <p><strong>WARNING</strong>: Concrete implementations of this interface must
* provide proper implementations of {@link Object#equals(Object)},
* {@link Object#hashCode()}, and {@link Object#toString()} in order to allow the
* filter to be used in caching scenarios &mdash; for example, in proxies generated
* by CGLIB. As of Spring Framework 6.0.13, the {@code toString()} implementation
* must generate a unique string representation that aligns with the logic used
* to implement {@code equals()}. See concrete implementations of this interface
* within the framework for examples.
*
* @author Rod Johnson
* @author Sam Brannen
* @see Pointcut
* @see MethodMatcher
*/
@@ -44,7 +49,7 @@ public interface ClassFilter {
/**
* Canonical instance of a ClassFilter that matches all classes.
* Canonical instance of a {@code ClassFilter} that matches all classes.
*/
ClassFilter TRUE = TrueClassFilter.INSTANCE;

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2019 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.
@@ -21,31 +21,37 @@ import java.lang.reflect.Method;
/**
* Part of a {@link Pointcut}: Checks whether the target method is eligible for advice.
*
* <p>A MethodMatcher may be evaluated <b>statically</b> or at <b>runtime</b> (dynamically).
* Static matching involves method and (possibly) method attributes. Dynamic matching
* also makes arguments for a particular call available, and any effects of running
* previous advice applying to the joinpoint.
* <p>A {@code MethodMatcher} may be evaluated <b>statically</b> or at <b>runtime</b>
* (dynamically). Static matching involves a method and (possibly) method attributes.
* Dynamic matching also makes arguments for a particular call available, and any
* effects of running previous advice applying to the joinpoint.
*
* <p>If an implementation returns {@code false} from its {@link #isRuntime()}
* method, evaluation can be performed statically, and the result will be the same
* for all invocations of this method, whatever their arguments. This means that
* if the {@link #isRuntime()} method returns {@code false}, the 3-arg
* {@link #matches(java.lang.reflect.Method, Class, Object[])} method will never be invoked.
* {@link #matches(Method, Class, Object[])} method will never be invoked.
*
* <p>If an implementation returns {@code true} from its 2-arg
* {@link #matches(java.lang.reflect.Method, Class)} method and its {@link #isRuntime()} method
* returns {@code true}, the 3-arg {@link #matches(java.lang.reflect.Method, Class, Object[])}
* method will be invoked <i>immediately before each potential execution of the related advice</i>,
* to decide whether the advice should run. All previous advice, such as earlier interceptors
* in an interceptor chain, will have run, so any state changes they have produced in
* parameters or ThreadLocal state will be available at the time of evaluation.
* {@link #matches(Method, Class)} method and its {@link #isRuntime()} method
* returns {@code true}, the 3-arg {@link #matches(Method, Class, Object[])}
* method will be invoked <i>immediately before each potential execution of the
* related advice</i> to decide whether the advice should run. All previous advice,
* such as earlier interceptors in an interceptor chain, will have run, so any
* state changes they have produced in parameters or {@code ThreadLocal} state will
* be available at the time of evaluation.
*
* <p>Concrete implementations of this interface typically should provide proper
* implementations of {@link Object#equals(Object)} and {@link Object#hashCode()}
* in order to allow the matcher to be used in caching scenarios &mdash; for
* example, in proxies generated by CGLIB.
* <p><strong>WARNING</strong>: Concrete implementations of this interface must
* provide proper implementations of {@link Object#equals(Object)},
* {@link Object#hashCode()}, and {@link Object#toString()} in order to allow the
* matcher to be used in caching scenarios &mdash; for example, in proxies generated
* by CGLIB. As of Spring Framework 6.0.13, the {@code toString()} implementation
* must generate a unique string representation that aligns with the logic used
* to implement {@code equals()}. See concrete implementations of this interface
* within the framework for examples.
*
* @author Rod Johnson
* @author Sam Brannen
* @since 11.11.2003
* @see Pointcut
* @see ClassFilter
@@ -53,11 +59,10 @@ import java.lang.reflect.Method;
public interface MethodMatcher {
/**
* Perform static checking whether the given method matches.
* <p>If this returns {@code false} or if the {@link #isRuntime()}
* method returns {@code false}, no runtime check (i.e. no
* {@link #matches(java.lang.reflect.Method, Class, Object[])} call)
* will be made.
* Perform static checking to determine whether the given method matches.
* <p>If this method returns {@code false} or if {@link #isRuntime()}
* returns {@code false}, no runtime check (i.e. no
* {@link #matches(Method, Class, Object[])} call) will be made.
* @param method the candidate method
* @param targetClass the target class
* @return whether this method matches statically
@@ -65,36 +70,35 @@ public interface MethodMatcher {
boolean matches(Method method, Class<?> targetClass);
/**
* Is this MethodMatcher dynamic, that is, must a final call be made on the
* {@link #matches(java.lang.reflect.Method, Class, Object[])} method at
* runtime even if the 2-arg matches method returns {@code true}?
* Is this {@code MethodMatcher} dynamic, that is, must a final check be made
* via the {@link #matches(Method, Class, Object[])} method at runtime even
* if {@link #matches(Method, Class)} returns {@code true}?
* <p>Can be invoked when an AOP proxy is created, and need not be invoked
* again before each method invocation,
* @return whether a runtime match via the 3-arg
* {@link #matches(java.lang.reflect.Method, Class, Object[])} method
* again before each method invocation.
* @return whether a runtime match via {@link #matches(Method, Class, Object[])}
* is required if static matching passed
*/
boolean isRuntime();
/**
* Check whether there a runtime (dynamic) match for this method,
* which must have matched statically.
* <p>This method is invoked only if the 2-arg matches method returns
* {@code true} for the given method and target class, and if the
* {@link #isRuntime()} method returns {@code true}. Invoked
* immediately before potential running of the advice, after any
* Check whether there is a runtime (dynamic) match for this method, which
* must have matched statically.
* <p>This method is invoked only if {@link #matches(Method, Class)} returns
* {@code true} for the given method and target class, and if
* {@link #isRuntime()} returns {@code true}.
* <p>Invoked immediately before potential running of the advice, after any
* advice earlier in the advice chain has run.
* @param method the candidate method
* @param targetClass the target class
* @param args arguments to the method
* @return whether there's a runtime match
* @see MethodMatcher#matches(Method, Class)
* @see #matches(Method, Class)
*/
boolean matches(Method method, Class<?> targetClass, Object... args);
/**
* Canonical instance that matches all methods.
* Canonical instance of a {@code MethodMatcher} that matches all methods.
*/
MethodMatcher TRUE = TrueMethodMatcher.INSTANCE;

View File

@@ -32,6 +32,7 @@ import org.springframework.aop.aspectj.annotation.AbstractAspectJAdvisorFactory.
import org.springframework.aop.support.DynamicMethodMatcherPointcut;
import org.springframework.aop.support.Pointcuts;
import org.springframework.lang.Nullable;
import org.springframework.util.ObjectUtils;
/**
* Internal implementation of AspectJPointcutAdvisor.
@@ -40,6 +41,7 @@ import org.springframework.lang.Nullable;
*
* @author Rod Johnson
* @author Juergen Hoeller
* @author Sam Brannen
* @since 2.0
*/
@SuppressWarnings("serial")
@@ -297,6 +299,23 @@ final class InstantiationModelAwarePointcutAdvisorImpl
private boolean isAspectMaterialized() {
return (this.aspectInstanceFactory == null || this.aspectInstanceFactory.isMaterialized());
}
@Override
public boolean equals(@Nullable Object other) {
return (this == other || (other instanceof PerTargetInstantiationModelPointcut that &&
ObjectUtils.nullSafeEquals(this.declaredPointcut.getExpression(), that.declaredPointcut.getExpression())));
}
@Override
public int hashCode() {
return ObjectUtils.nullSafeHashCode(this.declaredPointcut.getExpression());
}
@Override
public String toString() {
return PerTargetInstantiationModelPointcut.class.getName() + ": " + this.declaredPointcut.getExpression();
}
}
}

View File

@@ -48,7 +48,8 @@ import org.springframework.util.ObjectUtils;
/**
* Base class for AOP proxy configuration managers.
* These are not themselves AOP proxies, but subclasses of this class are
*
* <p>These are not themselves AOP proxies, but subclasses of this class are
* normally factories from which AOP proxy instances are obtained directly.
*
* <p>This class frees subclasses of the housekeeping of Advices
@@ -56,10 +57,12 @@ import org.springframework.util.ObjectUtils;
* methods, which are provided by subclasses.
*
* <p>This class is serializable; subclasses need not be.
* This class is used to hold snapshots of proxies.
*
* <p>This class is used to hold snapshots of proxies.
*
* @author Rod Johnson
* @author Juergen Hoeller
* @author Sam Brannen
* @see org.springframework.aop.framework.AopProxy
*/
public class AdvisedSupport extends ProxyConfig implements Advised {
@@ -111,7 +114,7 @@ public class AdvisedSupport extends ProxyConfig implements Advised {
}
/**
* Create a AdvisedSupport instance with the given parameters.
* Create an {@code AdvisedSupport} instance with the given parameters.
* @param interfaces the proxied interfaces
*/
public AdvisedSupport(Class<?>... interfaces) {
@@ -131,7 +134,7 @@ public class AdvisedSupport extends ProxyConfig implements Advised {
/**
* Set the given object as target.
* Will create a SingletonTargetSource for the object.
* <p>Will create a SingletonTargetSource for the object.
* @see #setTargetSource
* @see org.springframework.aop.target.SingletonTargetSource
*/
@@ -500,9 +503,9 @@ public class AdvisedSupport extends ProxyConfig implements Advised {
}
/**
* Copy the AOP configuration from the given AdvisedSupport object,
* but allow substitution of a fresh TargetSource and a given interceptor chain.
* @param other the AdvisedSupport object to take proxy configuration from
* Copy the AOP configuration from the given {@link AdvisedSupport} object,
* but allow substitution of a fresh {@link TargetSource} and a given interceptor chain.
* @param other the {@code AdvisedSupport} object to take proxy configuration from
* @param targetSource the new TargetSource
* @param advisors the Advisors for the chain
*/
@@ -522,8 +525,8 @@ public class AdvisedSupport extends ProxyConfig implements Advised {
}
/**
* Build a configuration-only copy of this AdvisedSupport,
* replacing the TargetSource.
* Build a configuration-only copy of this {@link AdvisedSupport},
* replacing the {@link TargetSource}.
*/
AdvisedSupport getConfigurationOnlyCopy() {
AdvisedSupport copy = new AdvisedSupport(this.advisorChainFactory, this.methodCache);
@@ -598,8 +601,7 @@ public class AdvisedSupport extends ProxyConfig implements Advised {
@Override
public boolean equals(@Nullable Object other) {
return (this == other || (other instanceof MethodCacheKey methodCacheKey &&
this.method == methodCacheKey.method));
return (this == other || (other instanceof MethodCacheKey that && this.method == that.method));
}
@Override
@@ -624,7 +626,7 @@ public class AdvisedSupport extends ProxyConfig implements Advised {
/**
* Stub for an Advisor instance that is just needed for key purposes,
* Stub for an {@link Advisor} instance that is just needed for key purposes,
* allowing for efficient equals and hashCode comparisons against the
* advice class and the pointcut.
* @since 6.0.10
@@ -636,17 +638,22 @@ public class AdvisedSupport extends ProxyConfig implements Advised {
private final Class<?> adviceType;
@Nullable
private String classFilterKey;
private final String classFilterKey;
@Nullable
private String methodMatcherKey;
private final String methodMatcherKey;
public AdvisorKeyEntry(Advisor advisor) {
this.adviceType = advisor.getAdvice().getClass();
if (advisor instanceof PointcutAdvisor pointcutAdvisor) {
Pointcut pointcut = pointcutAdvisor.getPointcut();
this.classFilterKey = ObjectUtils.identityToString(pointcut.getClassFilter());
this.methodMatcherKey = ObjectUtils.identityToString(pointcut.getMethodMatcher());
this.classFilterKey = pointcut.getClassFilter().toString();
this.methodMatcherKey = pointcut.getMethodMatcher().toString();
}
else {
this.classFilterKey = null;
this.methodMatcherKey = null;
}
}
@@ -657,10 +664,10 @@ public class AdvisedSupport extends ProxyConfig implements Advised {
@Override
public boolean equals(Object other) {
return (this == other || (other instanceof AdvisorKeyEntry otherEntry &&
this.adviceType == otherEntry.adviceType &&
ObjectUtils.nullSafeEquals(this.classFilterKey, otherEntry.classFilterKey) &&
ObjectUtils.nullSafeEquals(this.methodMatcherKey, otherEntry.methodMatcherKey)));
return (this == other || (other instanceof AdvisorKeyEntry that &&
this.adviceType == that.adviceType &&
ObjectUtils.nullSafeEquals(this.classFilterKey, that.classFilterKey) &&
ObjectUtils.nullSafeEquals(this.methodMatcherKey, that.methodMatcherKey)));
}
@Override

View File

@@ -40,10 +40,6 @@ import org.aspectj.lang.annotation.Pointcut;
import org.aspectj.lang.reflect.MethodSignature;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import test.aop.DefaultLockable;
import test.aop.Lockable;
import test.aop.PerTargetAspect;
import test.aop.TwoAdviceAspect;
import org.springframework.aop.Advisor;
import org.springframework.aop.framework.Advised;
@@ -51,6 +47,10 @@ import org.springframework.aop.framework.AopConfigException;
import org.springframework.aop.framework.ProxyFactory;
import org.springframework.aop.interceptor.ExposeInvocationInterceptor;
import org.springframework.aop.support.AopUtils;
import org.springframework.aop.testfixture.aspectj.PerTargetAspect;
import org.springframework.aop.testfixture.aspectj.TwoAdviceAspect;
import org.springframework.aop.testfixture.mixin.DefaultLockable;
import org.springframework.aop.testfixture.mixin.Lockable;
import org.springframework.beans.testfixture.beans.ITestBean;
import org.springframework.beans.testfixture.beans.TestBean;
import org.springframework.core.OrderComparator;
@@ -459,10 +459,10 @@ abstract class AbstractAspectJAdvisorFactoryTests {
assertThat(advisors).as("Two advice methods found").hasSize(2);
ITestBean itb = createProxy(target, ITestBean.class, advisors);
itb.setName("");
assertThat(itb.getAge()).isEqualTo(0);
assertThat(itb.age()).isEqualTo(0);
int newAge = 32;
itb.setAge(newAge);
assertThat(itb.getAge()).isEqualTo(1);
assertThat(itb.age()).isEqualTo(1);
}
@Test

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2020 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.
@@ -17,13 +17,13 @@
package org.springframework.aop.aspectj.annotation;
import org.junit.jupiter.api.Test;
import test.aop.PerTargetAspect;
import org.springframework.aop.Pointcut;
import org.springframework.aop.aspectj.AspectJExpressionPointcut;
import org.springframework.aop.aspectj.AspectJExpressionPointcutTests;
import org.springframework.aop.aspectj.annotation.AbstractAspectJAdvisorFactoryTests.ExceptionThrowingAspect;
import org.springframework.aop.framework.AopConfigException;
import org.springframework.aop.testfixture.aspectj.PerTargetAspect;
import org.springframework.beans.testfixture.beans.TestBean;
import static org.assertj.core.api.Assertions.assertThat;

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.
@@ -18,11 +18,11 @@ package org.springframework.aop.aspectj.annotation;
import org.aspectj.lang.reflect.PerClauseKind;
import org.junit.jupiter.api.Test;
import test.aop.PerTargetAspect;
import org.springframework.aop.Pointcut;
import org.springframework.aop.aspectj.AspectJExpressionPointcut;
import org.springframework.aop.aspectj.annotation.AbstractAspectJAdvisorFactoryTests.ExceptionThrowingAspect;
import org.springframework.aop.testfixture.aspectj.PerTargetAspect;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2020 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.
@@ -24,8 +24,8 @@ import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.junit.jupiter.api.Test;
import test.aop.PerThisAspect;
import org.springframework.aop.testfixture.aspectj.PerThisAspect;
import org.springframework.core.testfixture.io.SerializationTestUtils;
import static org.assertj.core.api.Assertions.assertThat;

View File

@@ -1,37 +0,0 @@
/*
* Copyright 2002-2005 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.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package test.aop;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
@Aspect("perthis(execution(* getAge()))")
public class PerThisAspect {
private int invocations = 0;
public int getInvocations() {
return this.invocations;
}
@Around("execution(* getAge())")
public int changeAge(ProceedingJoinPoint pjp) throws Throwable {
return invocations++;
}
}

View File

@@ -1,37 +0,0 @@
/*
* Copyright 2002-2008 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.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package test.aop;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
@Aspect
public class TwoAdviceAspect {
private int totalCalls;
@Around("execution(* getAge())")
public int returnCallCount(ProceedingJoinPoint pjp) throws Exception {
return totalCalls;
}
@Before("execution(* setAge(int)) && args(newAge)")
public void countSet(int newAge) throws Exception {
++totalCalls;
}
}

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
package test.aspect;
package org.springframework.aop.testfixture.aspectj;
import org.aspectj.lang.annotation.Pointcut;

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2014 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.
@@ -14,7 +14,7 @@
* limitations under the License.
*/
package test.aop;
package org.springframework.aop.testfixture.aspectj;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;

View File

@@ -14,13 +14,13 @@
* limitations under the License.
*/
package test.aspect;
package org.springframework.aop.testfixture.aspectj;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
@Aspect("perthis(test.aspect.CommonPointcuts.getAgeExecution())")
@Aspect("perthis(org.springframework.aop.testfixture.aspectj.CommonPointcuts.getAgeExecution())")
public class PerThisAspect {
private int invocations = 0;
@@ -29,7 +29,7 @@ public class PerThisAspect {
return this.invocations;
}
@Around("test.aspect.CommonPointcuts.getAgeExecution()")
@Around("org.springframework.aop.testfixture.aspectj.CommonPointcuts.getAgeExecution()")
public int changeAge(ProceedingJoinPoint pjp) {
return this.invocations++;
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2018 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.
@@ -14,7 +14,7 @@
* limitations under the License.
*/
package test.aspect;
package org.springframework.aop.testfixture.aspectj;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2012 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.
@@ -14,7 +14,7 @@
* limitations under the License.
*/
package test.aop;
package org.springframework.aop.testfixture.mixin;
/**
* Simple implementation of Lockable interface for use in mixins.

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2012 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.
@@ -14,7 +14,7 @@
* limitations under the License.
*/
package test.mixin;
package org.springframework.aop.testfixture.mixin;
import org.aopalliance.intercept.MethodInvocation;

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2012 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.
@@ -14,7 +14,7 @@
* limitations under the License.
*/
package test.mixin;
package org.springframework.aop.testfixture.mixin;
import org.springframework.aop.support.DefaultIntroductionAdvisor;

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2012 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.
@@ -14,14 +14,12 @@
* limitations under the License.
*/
package test.aop;
package org.springframework.aop.testfixture.mixin;
/**
* Simple interface to use for mixins
* Simple interface to use for mixins.
*
* @author Rod Johnson
*
*/
public interface Lockable {

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2012 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.
@@ -14,12 +14,12 @@
* limitations under the License.
*/
package test.mixin;
package org.springframework.aop.testfixture.mixin;
@SuppressWarnings("serial")
public class LockedException extends RuntimeException {
public LockedException() {
}
}

View File

@@ -27,11 +27,12 @@ import org.springframework.util.CollectionUtils;
import org.springframework.util.ObjectUtils;
/**
* A Pointcut that matches if the underlying {@link CacheOperationSource}
* A {@code Pointcut} that matches if the underlying {@link CacheOperationSource}
* has an attribute for a given method.
*
* @author Costin Leau
* @author Juergen Hoeller
* @author Sam Brannen
* @since 3.1
*/
@SuppressWarnings("serial")
@@ -86,6 +87,27 @@ class CacheOperationSourcePointcut extends StaticMethodMatcherPointcut implement
}
return (cacheOperationSource == null || cacheOperationSource.isCandidateClass(clazz));
}
private CacheOperationSource getCacheOperationSource() {
return cacheOperationSource;
}
@Override
public boolean equals(@Nullable Object other) {
return (this == other || (other instanceof CacheOperationSourceClassFilter that &&
ObjectUtils.nullSafeEquals(cacheOperationSource, that.getCacheOperationSource())));
}
@Override
public int hashCode() {
return CacheOperationSourceClassFilter.class.hashCode();
}
@Override
public String toString() {
return CacheOperationSourceClassFilter.class.getName() + ": " + cacheOperationSource;
}
}
}

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.
@@ -19,9 +19,9 @@ package org.springframework.aop.aspectj;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import test.mixin.Lockable;
import org.springframework.aop.support.AopUtils;
import org.springframework.aop.testfixture.mixin.Lockable;
import org.springframework.beans.testfixture.beans.ITestBean;
import org.springframework.context.support.ClassPathXmlApplicationContext;

View File

@@ -46,23 +46,25 @@ import org.springframework.aop.framework.ProxyConfig;
import org.springframework.aop.support.AbstractPointcutAdvisor;
import org.springframework.aop.support.AopUtils;
import org.springframework.aop.support.StaticMethodMatcherPointcutAdvisor;
import org.springframework.aop.testfixture.aspectj.PerTargetAspect;
import org.springframework.beans.PropertyValue;
import org.springframework.beans.factory.FactoryBean;
import org.springframework.beans.factory.config.MethodInvokingFactoryBean;
import org.springframework.beans.factory.support.RootBeanDefinition;
import org.springframework.beans.testfixture.beans.ITestBean;
import org.springframework.beans.testfixture.beans.TestBean;
import org.springframework.cglib.proxy.Factory;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.EnableAspectJAutoProxy;
import org.springframework.context.annotation.Scope;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.context.support.GenericApplicationContext;
import org.springframework.core.DecoratingProxy;
import org.springframework.core.NestedRuntimeException;
import org.springframework.core.Ordered;
import org.springframework.core.annotation.Order;
import org.springframework.lang.Nullable;
@@ -208,6 +210,31 @@ class AspectJAutoProxyCreatorTests {
assertThat(adrian1.getAge()).isEqualTo(3);
}
@Test // gh-31238
void cglibProxyClassIsCachedAcrossApplicationContextsForPerTargetAspect() {
Class<?> configClass = PerTargetProxyTargetClassTrueConfig.class;
TestBean testBean1;
TestBean testBean2;
// Round #1
try (ConfigurableApplicationContext context = new AnnotationConfigApplicationContext(configClass)) {
testBean1 = context.getBean(TestBean.class);
assertThat(AopUtils.isCglibProxy(testBean1)).as("CGLIB proxy").isTrue();
assertThat(testBean1.getClass().getInterfaces())
.containsExactlyInAnyOrder(Factory.class, SpringProxy.class, Advised.class);
}
// Round #2
try (ConfigurableApplicationContext context = new AnnotationConfigApplicationContext(configClass)) {
testBean2 = context.getBean(TestBean.class);
assertThat(AopUtils.isCglibProxy(testBean2)).as("CGLIB proxy").isTrue();
assertThat(testBean2.getClass().getInterfaces())
.containsExactlyInAnyOrder(Factory.class, SpringProxy.class, Advised.class);
}
assertThat(testBean1.getClass()).isSameAs(testBean2.getClass());
}
@Test
void twoAdviceAspect() {
ClassPathXmlApplicationContext bf = newContext("twoAdviceAspect.xml");
@@ -354,33 +381,6 @@ class AspectJAutoProxyCreatorTests {
}
@Aspect("pertarget(execution(* *.getSpouse()))")
class PerTargetAspect implements Ordered {
public int count;
private int order = Ordered.LOWEST_PRECEDENCE;
@Around("execution(int *.getAge())")
public int returnCountAsAge() {
return count++;
}
@Before("execution(void *.set*(int))")
public void countSetter() {
++count;
}
@Override
public int getOrder() {
return this.order;
}
public void setOrder(int order) {
this.order = order;
}
}
@Aspect
class AdviceUsingThisJoinPoint {
@@ -642,6 +642,23 @@ class ProxyTargetClassFalseConfig extends AbstractProxyTargetClassConfig {
class ProxyTargetClassTrueConfig extends AbstractProxyTargetClassConfig {
}
@Configuration
@EnableAspectJAutoProxy(proxyTargetClass = true)
class PerTargetProxyTargetClassTrueConfig {
@Bean
@Scope("prototype")
TestBean testBean() {
return new TestBean("Jane", 34);
}
@Bean
@Scope("prototype")
PerTargetAspect perTargetAspect() {
return new PerTargetAspect();
}
}
@FunctionalInterface
interface MessageGenerator {
String generateMessage();

View File

@@ -34,10 +34,6 @@ import org.aopalliance.intercept.MethodInvocation;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import test.mixin.LockMixin;
import test.mixin.LockMixinAdvisor;
import test.mixin.Lockable;
import test.mixin.LockedException;
import org.springframework.aop.Advisor;
import org.springframework.aop.AfterReturningAdvice;
@@ -64,6 +60,10 @@ import org.springframework.aop.testfixture.advice.MyThrowsHandler;
import org.springframework.aop.testfixture.interceptor.NopInterceptor;
import org.springframework.aop.testfixture.interceptor.SerializableNopInterceptor;
import org.springframework.aop.testfixture.interceptor.TimestampIntroductionInterceptor;
import org.springframework.aop.testfixture.mixin.LockMixin;
import org.springframework.aop.testfixture.mixin.LockMixinAdvisor;
import org.springframework.aop.testfixture.mixin.Lockable;
import org.springframework.aop.testfixture.mixin.LockedException;
import org.springframework.beans.testfixture.beans.IOther;
import org.springframework.beans.testfixture.beans.ITestBean;
import org.springframework.beans.testfixture.beans.Person;

View File

@@ -21,7 +21,6 @@ import java.io.Serializable;
import org.aopalliance.intercept.MethodInterceptor;
import org.aopalliance.intercept.MethodInvocation;
import org.junit.jupiter.api.Test;
import test.mixin.LockMixinAdvisor;
import org.springframework.aop.ClassFilter;
import org.springframework.aop.MethodMatcher;
@@ -31,6 +30,7 @@ import org.springframework.aop.support.DefaultPointcutAdvisor;
import org.springframework.aop.support.annotation.AnnotationMatchingPointcut;
import org.springframework.aop.testfixture.advice.CountingBeforeAdvice;
import org.springframework.aop.testfixture.interceptor.NopInterceptor;
import org.springframework.aop.testfixture.mixin.LockMixinAdvisor;
import org.springframework.beans.testfixture.beans.ITestBean;
import org.springframework.beans.testfixture.beans.TestBean;
import org.springframework.context.ApplicationContext;

View File

@@ -27,8 +27,6 @@ import org.aopalliance.intercept.MethodInterceptor;
import org.aopalliance.intercept.MethodInvocation;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import test.mixin.Lockable;
import test.mixin.LockedException;
import org.springframework.aop.ClassFilter;
import org.springframework.aop.IntroductionAdvisor;
@@ -42,6 +40,8 @@ import org.springframework.aop.testfixture.advice.CountingBeforeAdvice;
import org.springframework.aop.testfixture.advice.MyThrowsHandler;
import org.springframework.aop.testfixture.interceptor.NopInterceptor;
import org.springframework.aop.testfixture.interceptor.TimestampIntroductionInterceptor;
import org.springframework.aop.testfixture.mixin.Lockable;
import org.springframework.aop.testfixture.mixin.LockedException;
import org.springframework.beans.factory.BeanCreationException;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.FactoryBean;

View File

@@ -19,7 +19,6 @@ package org.springframework.aop.framework.autoproxy;
import java.io.IOException;
import org.junit.jupiter.api.Test;
import test.mixin.Lockable;
import org.springframework.aop.Advisor;
import org.springframework.aop.framework.Advised;
@@ -32,6 +31,7 @@ import org.springframework.aop.target.PrototypeTargetSource;
import org.springframework.aop.target.ThreadLocalTargetSource;
import org.springframework.aop.testfixture.advice.CountingBeforeAdvice;
import org.springframework.aop.testfixture.interceptor.NopInterceptor;
import org.springframework.aop.testfixture.mixin.Lockable;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.testfixture.beans.CountingTestBean;
import org.springframework.beans.testfixture.beans.ITestBean;

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2020 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.
@@ -17,13 +17,13 @@
package org.springframework.aop.framework.autoproxy;
import org.junit.jupiter.api.Test;
import test.mixin.Lockable;
import test.mixin.LockedException;
import org.springframework.aop.framework.Advised;
import org.springframework.aop.support.AopUtils;
import org.springframework.aop.testfixture.advice.CountingBeforeAdvice;
import org.springframework.aop.testfixture.interceptor.NopInterceptor;
import org.springframework.aop.testfixture.mixin.Lockable;
import org.springframework.aop.testfixture.mixin.LockedException;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.FactoryBean;
import org.springframework.beans.testfixture.beans.ITestBean;

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2021 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.
@@ -21,6 +21,7 @@ import java.util.concurrent.atomic.AtomicLong;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Test;
import org.springframework.aop.support.AopUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.Cache;
import org.springframework.cache.CacheManager;
@@ -45,6 +46,7 @@ import static org.springframework.context.testfixture.cache.CacheTestUtils.asser
* Tests that represent real use cases with advanced configuration.
*
* @author Stephane Nicoll
* @author Sam Brannen
*/
class EnableCachingIntegrationTests {
@@ -83,6 +85,25 @@ class EnableCachingIntegrationTests {
assertCacheHit(key, value, cache);
}
@Test // gh-31238
public void cglibProxyClassIsCachedAcrossApplicationContexts() {
ConfigurableApplicationContext ctx;
// Round #1
ctx = new AnnotationConfigApplicationContext(FooConfigCglib.class);
FooService service1 = ctx.getBean(FooService.class);
assertThat(AopUtils.isCglibProxy(service1)).as("FooService #1 is not a CGLIB proxy").isTrue();
ctx.close();
// Round #2
ctx = new AnnotationConfigApplicationContext(FooConfigCglib.class);
FooService service2 = ctx.getBean(FooService.class);
assertThat(AopUtils.isCglibProxy(service2)).as("FooService #2 is not a CGLIB proxy").isTrue();
ctx.close();
assertThat(service1.getClass()).isSameAs(service2.getClass());
}
@Test
void barServiceWithCacheableInterfaceCglib() {
this.context = new AnnotationConfigApplicationContext(BarConfigCglib.class);

View File

@@ -1,50 +0,0 @@
/*
* Copyright 2002-2018 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.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package test.aspect;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.springframework.core.Ordered;
@Aspect("pertarget(execution(* *.getSpouse()))")
public class PerTargetAspect implements Ordered {
public int count;
private int order = Ordered.LOWEST_PRECEDENCE;
@Around("execution(int *.getAge())")
public int returnCountAsAge() {
return count++;
}
@Before("execution(void *.set*(int))")
public void countSetter() {
++count;
}
@Override
public int getOrder() {
return this.order;
}
public void setOrder(int order) {
this.order = order;
}
}

View File

@@ -1,44 +0,0 @@
/*
* Copyright 2002-2018 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.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package test.mixin;
/**
* Simple implementation of Lockable interface for use in mixins.
*
* @author Rod Johnson
*/
public class DefaultLockable implements Lockable {
private boolean locked;
@Override
public void lock() {
this.locked = true;
}
@Override
public void unlock() {
this.locked = false;
}
@Override
public boolean locked() {
return this.locked;
}
}

View File

@@ -1,33 +0,0 @@
/*
* Copyright 2002-2018 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.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package test.mixin;
/**
* Simple interface to use for mixins
*
* @author Rod Johnson
*
*/
public interface Lockable {
void lock();
void unlock();
boolean locked();
}

View File

@@ -1,16 +1,16 @@
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:aop="http://www.springframework.org/schema/aop"
xsi:schemaLocation="http://www.springframework.org/schema/beans https://www.springframework.org/schema/beans/spring-beans-2.0.xsd
http://www.springframework.org/schema/aop https://www.springframework.org/schema/aop/spring-aop-2.0.xsd">
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:aop="http://www.springframework.org/schema/aop"
xsi:schemaLocation="http://www.springframework.org/schema/beans https://www.springframework.org/schema/beans/spring-beans-2.0.xsd
http://www.springframework.org/schema/aop https://www.springframework.org/schema/aop/spring-aop-2.0.xsd">
<aop:config>
<aop:aspect id="beforeAdviceBindingTests" ref="introduction">
<aop:declare-parents
types-matching="org.springframework.beans.testfixture.beans..*"
implement-interface="test.mixin.Lockable"
default-impl="test.mixin.DefaultLockable"
implement-interface="org.springframework.aop.testfixture.mixin.Lockable"
default-impl="org.springframework.aop.testfixture.mixin.DefaultLockable"
/>
<aop:before
method="checkNotLocked"

View File

@@ -5,8 +5,7 @@
<bean class="org.springframework.aop.aspectj.annotation.AnnotationAwareAspectJAutoProxyCreator"/>
<bean class="test.aspect.PerTargetAspect"
scope="prototype">
<bean class="org.springframework.aop.testfixture.aspectj.PerTargetAspect" scope="prototype">
<property name="order" value="5"/>
</bean>

View File

@@ -5,7 +5,7 @@
<bean class="org.springframework.aop.aspectj.annotation.AnnotationAwareAspectJAutoProxyCreator"/>
<bean class="test.aspect.PerThisAspect" scope="prototype"/>
<bean class="org.springframework.aop.testfixture.aspectj.PerThisAspect" scope="prototype"/>
<bean id="adrian" class="org.springframework.beans.testfixture.beans.TestBean" scope="prototype">
<property name="name" value="adrian"/>

View File

@@ -5,7 +5,7 @@
<bean class="org.springframework.aop.aspectj.annotation.AnnotationAwareAspectJAutoProxyCreator"/>
<bean id="aspect" class="test.aspect.TwoAdviceAspect"/>
<bean id="aspect" class="org.springframework.aop.testfixture.aspectj.TwoAdviceAspect"/>
<bean id="adrian" class="org.springframework.aop.framework.ProxyFactoryBean">
<property name="target">

View File

@@ -5,7 +5,7 @@
<bean class="org.springframework.aop.aspectj.annotation.AnnotationAwareAspectJAutoProxyCreator"/>
<bean id="aspect" class="test.aspect.TwoAdviceAspect" scope="prototype"/>
<bean id="aspect" class="org.springframework.aop.testfixture.aspectj.TwoAdviceAspect" scope="prototype"/>
<bean id="adrian" class="org.springframework.beans.testfixture.beans.TestBean" scope="prototype">
<property name="name" value="adrian"/>

View File

@@ -5,7 +5,7 @@
<bean class="org.springframework.aop.aspectj.annotation.AnnotationAwareAspectJAutoProxyCreator"/>
<bean id="aspect" class="test.aspect.TwoAdviceAspect"/>
<bean id="aspect" class="org.springframework.aop.testfixture.aspectj.TwoAdviceAspect"/>
<bean id="adrian" class="org.springframework.beans.testfixture.beans.TestBean" scope="prototype">
<property name="name" value="adrian"/>

View File

@@ -135,7 +135,7 @@
-->
<bean id="global_aspectInterface" class="org.springframework.aop.framework.ProxyFactoryBeanTests$GlobalIntroductionAdvice"/>
<bean id="prototypeLockMixinAdvisor" class="test.mixin.LockMixinAdvisor" scope="prototype"/>
<bean id="prototypeLockMixinAdvisor" class="org.springframework.aop.testfixture.mixin.LockMixinAdvisor" scope="prototype"/>
<bean id="prototypeTestBean" class="org.springframework.beans.testfixture.beans.TestBean" scope="prototype"/>
@@ -150,13 +150,13 @@
</property>
</bean>
<bean id="prototypeLockMixinInterceptor" class="test.mixin.LockMixin" scope="prototype"/>
<bean id="prototypeLockMixinInterceptor" class="org.springframework.aop.testfixture.mixin.LockMixin" scope="prototype"/>
<bean id="prototypeTestBeanProxySingletonTarget" class="org.springframework.aop.framework.ProxyFactoryBean">
<property name="interfaces">
<list>
<value>org.springframework.beans.testfixture.beans.ITestBean</value>
<value>test.mixin.Lockable</value>
<value>org.springframework.aop.testfixture.mixin.Lockable</value>
</list>
</property>
<property name="singleton"><value>false</value></property>

View File

@@ -31,7 +31,7 @@
</bean>
<!-- Stateful mixin. Will apply to all objects. Note that singleton property is false. -->
<bean id="lockableAdvisor" class="test.mixin.LockMixinAdvisor" scope="prototype"/>
<bean id="lockableAdvisor" class="org.springframework.aop.testfixture.mixin.LockMixinAdvisor" scope="prototype"/>
<bean id="test1" class="org.springframework.beans.testfixture.beans.TestBean">
<property name="age" value="4"/>

View File

@@ -54,8 +54,7 @@
<!--
Stateful mixin. Note that singleton property is false.
-->
<bean id="lockableAdvisor" class="test.mixin.LockMixinAdvisor"
scope="prototype"/>
<bean id="lockableAdvisor" class="org.springframework.aop.testfixture.mixin.LockMixinAdvisor" scope="prototype"/>
<bean id="countingBeforeAdvice" class="org.springframework.aop.testfixture.advice.CountingBeforeAdvice"/>

View File

@@ -27,14 +27,15 @@ import org.springframework.transaction.TransactionManager;
import org.springframework.util.ObjectUtils;
/**
* Abstract class that implements a Pointcut that matches if the underlying
* Internal class that implements a {@code Pointcut} that matches if the underlying
* {@link TransactionAttributeSource} has an attribute for a given method.
*
* @author Juergen Hoeller
* @author Sam Brannen
* @since 2.5.5
*/
@SuppressWarnings("serial")
class TransactionAttributeSourcePointcut extends StaticMethodMatcherPointcut implements Serializable {
final class TransactionAttributeSourcePointcut extends StaticMethodMatcherPointcut implements Serializable {
@Nullable
private TransactionAttributeSource transactionAttributeSource;
@@ -87,6 +88,27 @@ class TransactionAttributeSourcePointcut extends StaticMethodMatcherPointcut imp
}
return (transactionAttributeSource == null || transactionAttributeSource.isCandidateClass(clazz));
}
private TransactionAttributeSource getTransactionAttributeSource() {
return transactionAttributeSource;
}
@Override
public boolean equals(@Nullable Object other) {
return (this == other || (other instanceof TransactionAttributeSourceClassFilter that &&
ObjectUtils.nullSafeEquals(transactionAttributeSource, that.getTransactionAttributeSource())));
}
@Override
public int hashCode() {
return TransactionAttributeSourceClassFilter.class.hashCode();
}
@Override
public String toString() {
return TransactionAttributeSourceClassFilter.class.getName() + ": " + transactionAttributeSource;
}
}
}

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(