|
1 | 1 | /*
|
2 |
| - * Copyright 2014-2019 the original author or authors. |
| 2 | + * Copyright 2014-2020 the original author or authors. |
3 | 3 | *
|
4 | 4 | * Licensed under the Apache License, Version 2.0 (the "License");
|
5 | 5 | * you may not use this file except in compliance with the License.
|
|
16 | 16 |
|
17 | 17 | package org.springframework.amqp.rabbit.annotation;
|
18 | 18 |
|
| 19 | +import java.lang.reflect.AnnotatedElement; |
19 | 20 | import java.lang.reflect.Method;
|
20 | 21 | import java.nio.charset.Charset;
|
21 | 22 | import java.nio.charset.StandardCharsets;
|
|
31 | 32 | import java.util.concurrent.ConcurrentHashMap;
|
32 | 33 | import java.util.concurrent.ConcurrentMap;
|
33 | 34 | import java.util.concurrent.atomic.AtomicInteger;
|
| 35 | +import java.util.stream.Collectors; |
34 | 36 |
|
35 | 37 | import org.apache.commons.logging.Log;
|
36 | 38 | import org.apache.commons.logging.LogFactory;
|
|
69 | 71 | import org.springframework.context.expression.StandardBeanExpressionResolver;
|
70 | 72 | import org.springframework.core.Ordered;
|
71 | 73 | import org.springframework.core.annotation.AnnotationUtils;
|
72 |
| -import org.springframework.core.annotation.MergedAnnotation; |
73 | 74 | import org.springframework.core.annotation.MergedAnnotations;
|
74 | 75 | import org.springframework.core.annotation.MergedAnnotations.SearchStrategy;
|
75 | 76 | import org.springframework.core.convert.ConversionService;
|
@@ -331,36 +332,11 @@ private TypeMetadata buildMetadata(Class<?> targetClass) {
|
331 | 332 | classLevelListeners.toArray(new RabbitListener[classLevelListeners.size()]));
|
332 | 333 | }
|
333 | 334 |
|
334 |
| - /* |
335 |
| - * AnnotationUtils.getRepeatableAnnotations does not look at interfaces |
336 |
| - */ |
337 |
| - private Collection<RabbitListener> findListenerAnnotations(Class<?> clazz) { |
338 |
| - Set<RabbitListener> listeners = new HashSet<>(); |
339 |
| - RabbitListener ann = AnnotationUtils.findAnnotation(clazz, RabbitListener.class); |
340 |
| - if (ann != null) { |
341 |
| - listeners.add(ann); |
342 |
| - } |
343 |
| - RabbitListeners anns = AnnotationUtils.findAnnotation(clazz, RabbitListeners.class); |
344 |
| - if (anns != null) { |
345 |
| - Collections.addAll(listeners, anns.value()); |
346 |
| - } |
347 |
| - return listeners; |
348 |
| - } |
349 |
| - |
350 |
| - /* |
351 |
| - * AnnotationUtils.getRepeatableAnnotations does not look at interfaces |
352 |
| - */ |
353 |
| - private Collection<RabbitListener> findListenerAnnotations(Method method) { |
354 |
| - Set<RabbitListener> listeners = new HashSet<RabbitListener>(); |
355 |
| - RabbitListener ann = AnnotationUtils.findAnnotation(method, RabbitListener.class); |
356 |
| - if (ann != null) { |
357 |
| - listeners.add(ann); |
358 |
| - } |
359 |
| - RabbitListeners anns = AnnotationUtils.findAnnotation(method, RabbitListeners.class); |
360 |
| - if (anns != null) { |
361 |
| - Collections.addAll(listeners, anns.value()); |
362 |
| - } |
363 |
| - return listeners; |
| 335 | + private Collection<RabbitListener> findListenerAnnotations(AnnotatedElement element) { |
| 336 | + return MergedAnnotations.from(element, SearchStrategy.TYPE_HIERARCHY) |
| 337 | + .stream(RabbitListener.class) |
| 338 | + .map(ann -> ann.synthesize()) |
| 339 | + .collect(Collectors.toList()); |
364 | 340 | }
|
365 | 341 |
|
366 | 342 | private void processMultiMethodListeners(RabbitListener[] classLevelListeners, Method[] multiMethods,
|
@@ -424,10 +400,9 @@ private Method checkProxy(Method methodArg, Object bean) {
|
424 | 400 | return method;
|
425 | 401 | }
|
426 | 402 |
|
427 |
| - protected void processListener(MethodRabbitListenerEndpoint endpoint, RabbitListener rabbitListenerArg, Object bean, |
| 403 | + protected void processListener(MethodRabbitListenerEndpoint endpoint, RabbitListener rabbitListener, Object bean, |
428 | 404 | Object target, String beanName) {
|
429 | 405 |
|
430 |
| - RabbitListener rabbitListener = synthesizeIfPossible(endpoint, rabbitListenerArg, target); |
431 | 406 | endpoint.setBean(bean);
|
432 | 407 | endpoint.setMessageHandlerMethodFactory(this.messageHandlerMethodFactory);
|
433 | 408 | endpoint.setId(getEndpointId(rabbitListener));
|
@@ -481,33 +456,6 @@ else if (errorHandler instanceof String) {
|
481 | 456 | this.registrar.registerEndpoint(endpoint, factory);
|
482 | 457 | }
|
483 | 458 |
|
484 |
| - private RabbitListener synthesizeIfPossible(MethodRabbitListenerEndpoint endpoint, RabbitListener rabbitListenerArg, |
485 |
| - Object target) { |
486 |
| - |
487 |
| - RabbitListener rabbitListener = rabbitListenerArg; |
488 |
| - MergedAnnotation<RabbitListener> mergedAnnotation = MergedAnnotation.missing(); |
489 |
| - /* |
490 |
| - * Synthesize the actual annotation to handle meta-annotations and aliasing. Note |
491 |
| - * that only single @RabbitListener annotations can be meta-annotated. |
492 |
| - */ |
493 |
| - if (endpoint instanceof MultiMethodRabbitListenerEndpoint) { |
494 |
| - if (AnnotationUtils.findAnnotation((Class<?>) target, RabbitListeners.class) == null) { |
495 |
| - mergedAnnotation = MergedAnnotations.from((Class<?>) target, SearchStrategy.TYPE_HIERARCHY) |
496 |
| - .get(RabbitListener.class); |
497 |
| - } |
498 |
| - } |
499 |
| - else { |
500 |
| - if (AnnotationUtils.findAnnotation(endpoint.getMethod(), RabbitListeners.class) == null) { |
501 |
| - mergedAnnotation = MergedAnnotations.from(endpoint.getMethod(), SearchStrategy.TYPE_HIERARCHY) |
502 |
| - .get(RabbitListener.class); |
503 |
| - } |
504 |
| - } |
505 |
| - if (!MergedAnnotation.missing().equals(mergedAnnotation)) { |
506 |
| - rabbitListener = mergedAnnotation.synthesize(); |
507 |
| - } |
508 |
| - return rabbitListener; |
509 |
| - } |
510 |
| - |
511 | 459 | private void resolveAckMode(MethodRabbitListenerEndpoint endpoint, RabbitListener rabbitListener) {
|
512 | 460 | String ackModeAttr = rabbitListener.ackMode();
|
513 | 461 | if (StringUtils.hasText(ackModeAttr)) {
|
|
0 commit comments