diff --git a/spring-aop/src/main/java/org/springframework/aop/framework/AopProxyUtils.java b/spring-aop/src/main/java/org/springframework/aop/framework/AopProxyUtils.java index 0deb980516..4d38c93e55 100644 --- a/spring-aop/src/main/java/org/springframework/aop/framework/AopProxyUtils.java +++ b/spring-aop/src/main/java/org/springframework/aop/framework/AopProxyUtils.java @@ -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); diff --git a/spring-context/src/test/java/org/springframework/aop/framework/autoproxy/AutoProxyCreatorTests.java b/spring-context/src/test/java/org/springframework/aop/framework/autoproxy/AutoProxyCreatorTests.java index 161537686f..acaa8b72f6 100644 --- a/spring-context/src/test/java/org/springframework/aop/framework/autoproxy/AutoProxyCreatorTests.java +++ b/spring-context/src/test/java/org/springframework/aop/framework/autoproxy/AutoProxyCreatorTests.java @@ -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 { 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 { } } + + public static class SpringProxyFactoryBean implements FactoryBean { + + 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; + } + } + }