diff --git a/org.springframework.integration/src/main/java/org/springframework/integration/config/annotation/PublisherAnnotationPostProcessor.java b/org.springframework.integration/src/main/java/org/springframework/integration/config/annotation/PublisherAnnotationPostProcessor.java index 168dcaafa9..8fdc83966d 100644 --- a/org.springframework.integration/src/main/java/org/springframework/integration/config/annotation/PublisherAnnotationPostProcessor.java +++ b/org.springframework.integration/src/main/java/org/springframework/integration/config/annotation/PublisherAnnotationPostProcessor.java @@ -17,6 +17,8 @@ package org.springframework.integration.config.annotation; import java.lang.annotation.Annotation; +import java.lang.reflect.Method; +import java.util.concurrent.atomic.AtomicBoolean; import org.springframework.aop.Advisor; import org.springframework.aop.framework.Advised; @@ -25,10 +27,12 @@ import org.springframework.aop.support.AopUtils; import org.springframework.beans.BeansException; import org.springframework.beans.factory.BeanClassLoaderAware; import org.springframework.beans.factory.config.BeanPostProcessor; +import org.springframework.core.annotation.AnnotationUtils; import org.springframework.integration.annotation.Publisher; import org.springframework.integration.aop.PublisherAnnotationAdvisor; import org.springframework.integration.channel.ChannelRegistry; import org.springframework.util.Assert; +import org.springframework.util.ReflectionUtils; /** * A {@link BeanPostProcessor} that adds a message publishing interceptor when @@ -96,6 +100,7 @@ public class PublisherAnnotationPostProcessor implements BeanPostProcessor, Bean } else { ProxyFactory pf = new ProxyFactory(bean); + pf.setProxyTargetClass(this.requiresClassProxying(targetClass)); pf.addAdvisor(this.advisor); return pf.getProxy(this.beanClassLoader); } @@ -105,4 +110,29 @@ public class PublisherAnnotationPostProcessor implements BeanPostProcessor, Bean } } + private boolean requiresClassProxying(Class targetClass) { + final AtomicBoolean result = new AtomicBoolean(false); + final Class[] interfaces = targetClass.getInterfaces(); + ReflectionUtils.doWithMethods(targetClass, new ReflectionUtils.MethodCallback() { + public void doWith(Method method) throws IllegalArgumentException, IllegalAccessException { + Annotation annotation = AnnotationUtils.findAnnotation(method, publisherAnnotationType); + if (annotation != null) { + boolean foundMethodOnInterface = false; + for (Class iface : interfaces) { + Method ifaceMethod = ReflectionUtils.findMethod( + iface, method.getName(), method.getParameterTypes()); + if (ifaceMethod != null) { + foundMethodOnInterface = true; + break; + } + } + if (!foundMethodOnInterface) { + result.set(true); + } + } + } + }); + return result.get(); + } + } diff --git a/org.springframework.integration/src/test/java/org/springframework/integration/aop/ITestBean.java b/org.springframework.integration/src/test/java/org/springframework/integration/aop/ITestBean.java index 1a8fbd71eb..a8cec0629c 100644 --- a/org.springframework.integration/src/test/java/org/springframework/integration/aop/ITestBean.java +++ b/org.springframework.integration/src/test/java/org/springframework/integration/aop/ITestBean.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2007 the original author or authors. + * Copyright 2002-2008 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. diff --git a/org.springframework.integration/src/test/java/org/springframework/integration/aop/PublisherAnnotationTestBean.java b/org.springframework.integration/src/test/java/org/springframework/integration/aop/PublisherAnnotationTestBean.java index 2470e05845..cacad2a509 100644 --- a/org.springframework.integration/src/test/java/org/springframework/integration/aop/PublisherAnnotationTestBean.java +++ b/org.springframework.integration/src/test/java/org/springframework/integration/aop/PublisherAnnotationTestBean.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2007 the original author or authors. + * Copyright 2002-2008 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.