Skip to content

Commit adfac79

Browse files
jhoellerBenjamin Reed
authored andcommitted
Avoid repeated exposure of SpringProxy/Advised for fallback interfaces as well
Issue: SPR-12870
1 parent 7acac10 commit adfac79

File tree

2 files changed

+27
-3
lines changed

2 files changed

+27
-3
lines changed

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,11 +86,12 @@ public static Class<?>[] completeProxiedInterfaces(AdvisedSupport advised) {
8686
Class<?> targetClass = advised.getTargetClass();
8787
if (targetClass != null) {
8888
if (targetClass.isInterface()) {
89-
specifiedInterfaces = new Class<?>[] {targetClass};
89+
advised.setInterfaces(targetClass);
9090
}
9191
else if (Proxy.isProxyClass(targetClass)) {
92-
specifiedInterfaces = targetClass.getInterfaces();
92+
advised.setInterfaces(targetClass.getInterfaces());
9393
}
94+
specifiedInterfaces = advised.getProxiedInterfaces();
9495
}
9596
}
9697
boolean addSpringProxy = !advised.isInterfaceProxied(SpringProxy.class);

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

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,9 @@
2626
import org.junit.Test;
2727

2828
import org.springframework.aop.TargetSource;
29+
import org.springframework.aop.framework.ProxyFactory;
2930
import org.springframework.aop.support.AopUtils;
31+
import org.springframework.aop.target.SingletonTargetSource;
3032
import org.springframework.beans.MutablePropertyValues;
3133
import org.springframework.beans.factory.BeanFactory;
3234
import org.springframework.beans.factory.BeanFactoryAware;
@@ -222,7 +224,7 @@ public void testAutoProxyCreatorWithFallbackToDynamicProxy() {
222224
sac.registerSingleton("containerCallbackInterfacesOnly", ContainerCallbackInterfacesOnly.class);
223225
sac.registerSingleton("singletonNoInterceptor", CustomProxyFactoryBean.class);
224226
sac.registerSingleton("singletonToBeProxied", CustomProxyFactoryBean.class);
225-
sac.registerPrototype("prototypeToBeProxied", CustomProxyFactoryBean.class);
227+
sac.registerPrototype("prototypeToBeProxied", SpringProxyFactoryBean.class);
226228

227229
sac.refresh();
228230

@@ -473,4 +475,25 @@ public boolean isSingleton() {
473475
}
474476
}
475477

478+
479+
public static class SpringProxyFactoryBean implements FactoryBean<ITestBean> {
480+
481+
private final TestBean tb = new TestBean();
482+
483+
@Override
484+
public ITestBean getObject() {
485+
return ProxyFactory.getProxy(ITestBean.class, new SingletonTargetSource(tb));
486+
}
487+
488+
@Override
489+
public Class<?> getObjectType() {
490+
return ITestBean.class;
491+
}
492+
493+
@Override
494+
public boolean isSingleton() {
495+
return false;
496+
}
497+
}
498+
476499
}

0 commit comments

Comments
 (0)