Cache CGLIB proxy classes properly again
The introduction of AdvisedSupport.AdvisorKeyEntry in Spring Framework 6.0.10 resulted in a regression regarding caching of CGLIB generated proxy classes. Specifically, equality checks for the proxy class cache became based partially on identity rather than equivalence. For example, if an ApplicationContext was configured to create a class-based @Transactional proxy, a second attempt to create the ApplicationContext resulted in a duplicate proxy class for the same @Transactional component. On the JVM this went unnoticed; however, when running Spring integration tests within a native image, if a test made use of @DirtiesContext, a second attempt to create the test ApplicationContext resulted in an exception stating, "CGLIB runtime enhancement not supported on native image." This is because Test AOT processing only refreshes a test ApplicationContext once, and the duplicate CGLIB proxy classes are only requested in subsequent refreshes of the same ApplicationContext which means that duplicate proxy classes are not tracked during AOT processing and consequently not included in a native image. This commit addresses this regression as follows. - AdvisedSupport.AdvisorKeyEntry is now based on the toString() representations of the ClassFilter and MethodMatcher in the corresponding Pointcut instead of the filter's and matcher's identities. - Due to the above changes to AdvisorKeyEntry, ClassFilter and MethodMatcher implementations are now required to implement equals(), hashCode(), AND toString(). - Consequently, the following now include proper equals(), hashCode(), and toString() implementations. - CacheOperationSourcePointcut - TransactionAttributeSourcePointcut - PerTargetInstantiationModelPointcut Closes gh-31238
This commit is contained in:
@@ -27,14 +27,15 @@ import org.springframework.transaction.TransactionManager;
|
||||
import org.springframework.util.ObjectUtils;
|
||||
|
||||
/**
|
||||
* Abstract class that implements a {@code 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;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user