AspectJExpressionPointcut consistently resolves superinterface methods

Includes efficient check for same ClassLoader in ClassUtils.isVisible, efficient MethodMatchers check for IntroductionAwareMethodMatcher, and supertype method resolution in MethodMapTransactionAttributeSource.

Issue: SPR-16723

(cherry picked from commit b95e05d)
This commit is contained in:
Juergen Hoeller
2018-04-14 15:10:05 +02:00
parent bbe850d33a
commit b5922f75bb
13 changed files with 179 additions and 77 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2017 the original author or authors.
* 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.
@@ -32,6 +32,7 @@ import org.springframework.util.Assert;
import org.springframework.util.ClassUtils;
import org.springframework.util.ObjectUtils;
import org.springframework.util.PatternMatchUtils;
import org.springframework.util.ReflectionUtils;
/**
* Simple {@link TransactionAttributeSource} implementation that
@@ -144,7 +145,7 @@ public class MethodMapTransactionAttributeSource
Assert.notNull(mappedName, "Mapped name must not be null");
String name = clazz.getName() + '.' + mappedName;
Method[] methods = clazz.getDeclaredMethods();
Method[] methods = ReflectionUtils.getAllDeclaredMethods(clazz);
List<Method> matchingMethods = new ArrayList<>();
for (Method method : methods) {
if (isMatch(method.getName(), mappedName)) {
@@ -156,7 +157,7 @@ public class MethodMapTransactionAttributeSource
"Couldn't find method '" + mappedName + "' on class [" + clazz.getName() + "]");
}
// register all matching methods
// Register all matching methods
for (Method method : matchingMethods) {
String regMethodName = this.methodNameMap.get(method);
if (regMethodName == null || (!regMethodName.equals(name) && regMethodName.length() <= name.length())) {

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2015 the original author or authors.
* 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.
@@ -45,7 +45,6 @@ import org.springframework.transaction.TransactionStatus;
import static org.junit.Assert.*;
import static org.mockito.BDDMockito.*;
/**
* Test cases for AOP transaction management.
*
@@ -67,7 +66,7 @@ public class BeanFactoryTransactionTests {
@Test
public void testGetsAreNotTransactionalWithProxyFactory1() throws NoSuchMethodException {
public void testGetsAreNotTransactionalWithProxyFactory1() {
ITestBean testBean = (ITestBean) factory.getBean("proxyFactory1");
assertTrue("testBean is a dynamic proxy", Proxy.isProxyClass(testBean.getClass()));
assertFalse(testBean instanceof TransactionalProxy);
@@ -75,7 +74,7 @@ public class BeanFactoryTransactionTests {
}
@Test
public void testGetsAreNotTransactionalWithProxyFactory2DynamicProxy() throws NoSuchMethodException {
public void testGetsAreNotTransactionalWithProxyFactory2DynamicProxy() {
this.factory.preInstantiateSingletons();
ITestBean testBean = (ITestBean) factory.getBean("proxyFactory2DynamicProxy");
assertTrue("testBean is a dynamic proxy", Proxy.isProxyClass(testBean.getClass()));
@@ -84,7 +83,7 @@ public class BeanFactoryTransactionTests {
}
@Test
public void testGetsAreNotTransactionalWithProxyFactory2Cglib() throws NoSuchMethodException {
public void testGetsAreNotTransactionalWithProxyFactory2Cglib() {
ITestBean testBean = (ITestBean) factory.getBean("proxyFactory2Cglib");
assertTrue("testBean is CGLIB advised", AopUtils.isCglibProxy(testBean));
assertTrue(testBean instanceof TransactionalProxy);
@@ -92,7 +91,7 @@ public class BeanFactoryTransactionTests {
}
@Test
public void testProxyFactory2Lazy() throws NoSuchMethodException {
public void testProxyFactory2Lazy() {
ITestBean testBean = (ITestBean) factory.getBean("proxyFactory2Lazy");
assertFalse(factory.containsSingleton("target"));
assertEquals(666, testBean.getAge());
@@ -100,7 +99,7 @@ public class BeanFactoryTransactionTests {
}
@Test
public void testCglibTransactionProxyImplementsNoInterfaces() throws NoSuchMethodException {
public void testCglibTransactionProxyImplementsNoInterfaces() {
ImplementsNoInterfaces ini = (ImplementsNoInterfaces) factory.getBean("cglibNoInterfaces");
assertTrue("testBean is CGLIB advised", AopUtils.isCglibProxy(ini));
assertTrue(ini instanceof TransactionalProxy);
@@ -116,7 +115,7 @@ public class BeanFactoryTransactionTests {
}
@Test
public void testGetsAreNotTransactionalWithProxyFactory3() throws NoSuchMethodException {
public void testGetsAreNotTransactionalWithProxyFactory3() {
ITestBean testBean = (ITestBean) factory.getBean("proxyFactory3");
assertTrue("testBean is a full proxy", testBean instanceof DerivedTestBean);
assertTrue(testBean instanceof TransactionalProxy);
@@ -202,7 +201,7 @@ public class BeanFactoryTransactionTests {
* Test that we can set the target to a dynamic TargetSource.
*/
@Test
public void testDynamicTargetSource() throws NoSuchMethodException {
public void testDynamicTargetSource() {
// Install facade
CallCountingTransactionManager txMan = new CallCountingTransactionManager();
PlatformTransactionManagerFacade.delegate = txMan;