Browse Source

Avoid repeated exposure of SpringProxy/Advised for fallback interfaces as well

Issue: SPR-12870
pull/766/head
Juergen Hoeller 10 years ago
parent
commit
e1395a6c68
  1. 5
      spring-aop/src/main/java/org/springframework/aop/framework/AopProxyUtils.java
  2. 25
      spring-context/src/test/java/org/springframework/aop/framework/autoproxy/AutoProxyCreatorTests.java

5
spring-aop/src/main/java/org/springframework/aop/framework/AopProxyUtils.java

@ -86,11 +86,12 @@ public abstract class AopProxyUtils { @@ -86,11 +86,12 @@ public abstract class AopProxyUtils {
Class<?> targetClass = advised.getTargetClass();
if (targetClass != null) {
if (targetClass.isInterface()) {
specifiedInterfaces = new Class<?>[] {targetClass};
advised.setInterfaces(targetClass);
}
else if (Proxy.isProxyClass(targetClass)) {
specifiedInterfaces = targetClass.getInterfaces();
advised.setInterfaces(targetClass.getInterfaces());
}
specifiedInterfaces = advised.getProxiedInterfaces();
}
}
boolean addSpringProxy = !advised.isInterfaceProxied(SpringProxy.class);

25
spring-context/src/test/java/org/springframework/aop/framework/autoproxy/AutoProxyCreatorTests.java

@ -26,7 +26,9 @@ import org.aopalliance.intercept.MethodInvocation; @@ -26,7 +26,9 @@ import org.aopalliance.intercept.MethodInvocation;
import org.junit.Test;
import org.springframework.aop.TargetSource;
import org.springframework.aop.framework.ProxyFactory;
import org.springframework.aop.support.AopUtils;
import org.springframework.aop.target.SingletonTargetSource;
import org.springframework.beans.MutablePropertyValues;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.BeanFactoryAware;
@ -222,7 +224,7 @@ public final class AutoProxyCreatorTests { @@ -222,7 +224,7 @@ public final class AutoProxyCreatorTests {
sac.registerSingleton("containerCallbackInterfacesOnly", ContainerCallbackInterfacesOnly.class);
sac.registerSingleton("singletonNoInterceptor", CustomProxyFactoryBean.class);
sac.registerSingleton("singletonToBeProxied", CustomProxyFactoryBean.class);
sac.registerPrototype("prototypeToBeProxied", CustomProxyFactoryBean.class);
sac.registerPrototype("prototypeToBeProxied", SpringProxyFactoryBean.class);
sac.refresh();
@ -473,4 +475,25 @@ public final class AutoProxyCreatorTests { @@ -473,4 +475,25 @@ public final class AutoProxyCreatorTests {
}
}
public static class SpringProxyFactoryBean implements FactoryBean<ITestBean> {
private final TestBean tb = new TestBean();
@Override
public ITestBean getObject() {
return ProxyFactory.getProxy(ITestBean.class, new SingletonTargetSource(tb));
}
@Override
public Class<?> getObjectType() {
return ITestBean.class;
}
@Override
public boolean isSingleton() {
return false;
}
}
}

Loading…
Cancel
Save