From a67fe02fd711f8ef26e25c0d90e553cf1310c3b8 Mon Sep 17 00:00:00 2001 From: Marius Bogoevici Date: Tue, 7 Mar 2017 14:32:07 -0500 Subject: [PATCH] Handle `@StreamListener` properly as meta-annotation Fix #841 * Use `AnnotatedElementUtils` * Formatting for the additional test --- .../StreamListenerAsMetaAnnotationTests.java | 25 ++++++++++++++++--- ...amListenerAnnotationBeanPostProcessor.java | 3 ++- 2 files changed, 24 insertions(+), 4 deletions(-) diff --git a/spring-cloud-stream-integration-tests/src/test/java/org/springframework/cloud/stream/config/StreamListenerAsMetaAnnotationTests.java b/spring-cloud-stream-integration-tests/src/test/java/org/springframework/cloud/stream/config/StreamListenerAsMetaAnnotationTests.java index 712f18cc8..13c85c708 100644 --- a/spring-cloud-stream-integration-tests/src/test/java/org/springframework/cloud/stream/config/StreamListenerAsMetaAnnotationTests.java +++ b/spring-cloud-stream-integration-tests/src/test/java/org/springframework/cloud/stream/config/StreamListenerAsMetaAnnotationTests.java @@ -1,6 +1,20 @@ -package org.springframework.cloud.stream.config; +/* + * Copyright 2017 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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ -import static org.assertj.core.api.Assertions.assertThat; +package org.springframework.cloud.stream.config; import java.lang.annotation.Documented; import java.lang.annotation.ElementType; @@ -12,6 +26,7 @@ import java.util.List; import java.util.UUID; import org.junit.Test; + import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.EnableAutoConfiguration; import org.springframework.cloud.stream.annotation.EnableBinding; @@ -23,7 +38,11 @@ import org.springframework.integration.support.MessageBuilder; import org.springframework.messaging.handler.annotation.MessageMapping; import org.springframework.messaging.handler.annotation.Payload; +import static org.assertj.core.api.Assertions.assertThat; +/** + * @author David Turanski + */ public class StreamListenerAsMetaAnnotationTests { @Test @@ -118,4 +137,4 @@ public class StreamListenerAsMetaAnnotationTests { @AliasFor(annotation=StreamListener.class, attribute="condition") String condition() default ""; -} \ No newline at end of file +} diff --git a/spring-cloud-stream/src/main/java/org/springframework/cloud/stream/binding/StreamListenerAnnotationBeanPostProcessor.java b/spring-cloud-stream/src/main/java/org/springframework/cloud/stream/binding/StreamListenerAnnotationBeanPostProcessor.java index 5b09089ce..3d7e3d0ea 100644 --- a/spring-cloud-stream/src/main/java/org/springframework/cloud/stream/binding/StreamListenerAnnotationBeanPostProcessor.java +++ b/spring-cloud-stream/src/main/java/org/springframework/cloud/stream/binding/StreamListenerAnnotationBeanPostProcessor.java @@ -45,6 +45,7 @@ import org.springframework.context.ApplicationContextAware; import org.springframework.context.ConfigurableApplicationContext; import org.springframework.context.annotation.Lazy; import org.springframework.core.MethodParameter; +import org.springframework.core.annotation.AnnotatedElementUtils; import org.springframework.core.annotation.AnnotationUtils; import org.springframework.expression.EvaluationContext; import org.springframework.expression.Expression; @@ -139,7 +140,7 @@ public class StreamListenerAnnotationBeanPostProcessor ReflectionUtils.doWithMethods(targetClass, new ReflectionUtils.MethodCallback() { @Override public void doWith(final Method method) throws IllegalArgumentException, IllegalAccessException { - StreamListener streamListener = AnnotationUtils.findAnnotation(method, StreamListener.class); + StreamListener streamListener = AnnotatedElementUtils.findMergedAnnotation(method, StreamListener.class); if (streamListener != null && !method.isBridge()) { streamListener = postProcessAnnotation(streamListener, method); Assert.isTrue(method.getAnnotation(Input.class) == null,