Fix detection of the @SendTo annotation
Previously, the default reply destination could not be discovered if the @JmsListener annotation was placed on a bean that is eligible for proxying as the proxy method is used internally and does not reveal an annotation placed on the implementation. This commit makes sure to resolve the most specific method when searching that annotation. Issue: SPR-12513
This commit is contained in:
@@ -19,6 +19,8 @@ package org.springframework.jms.config;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.Arrays;
|
||||
|
||||
import org.springframework.aop.framework.AopProxyUtils;
|
||||
import org.springframework.aop.support.AopUtils;
|
||||
import org.springframework.core.annotation.AnnotationUtils;
|
||||
import org.springframework.jms.listener.MessageListenerContainer;
|
||||
import org.springframework.jms.listener.adapter.MessagingMessageListenerAdapter;
|
||||
@@ -109,18 +111,29 @@ public class MethodJmsListenerEndpoint extends AbstractJmsListenerEndpoint {
|
||||
}
|
||||
|
||||
private String getDefaultResponseDestination() {
|
||||
SendTo ann = AnnotationUtils.getAnnotation(getMethod(), SendTo.class);
|
||||
Method specificMethod = getMostSpecificMethod();
|
||||
SendTo ann = AnnotationUtils.getAnnotation(specificMethod, SendTo.class);
|
||||
if (ann != null) {
|
||||
Object[] destinations = ann.value();
|
||||
if (destinations.length != 1) {
|
||||
throw new IllegalStateException("Invalid @" + SendTo.class.getSimpleName() + " annotation on '"
|
||||
+ getMethod() + "' one destination must be set (got " + Arrays.toString(destinations) + ")");
|
||||
+ specificMethod + "' one destination must be set (got " + Arrays.toString(destinations) + ")");
|
||||
}
|
||||
return (String) destinations[0];
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private Method getMostSpecificMethod() {
|
||||
if (AopUtils.isAopProxy(this.bean)) {
|
||||
Class<?> target = AopProxyUtils.ultimateTargetClass(this.bean);
|
||||
return AopUtils.getMostSpecificMethod(getMethod(), target);
|
||||
}
|
||||
else {
|
||||
return getMethod();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected StringBuilder getEndpointDescription() {
|
||||
return super.getEndpointDescription()
|
||||
|
||||
Reference in New Issue
Block a user