Support expression in @SendTo
The attributes of @JmsListener allows to specify the reference to a key in the Environment but @SendTo did not. This commit fixes this inconsistency so that response destinations are now also externally configurable. Issue: SPR-12899
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2014 the original author or authors.
|
||||
* Copyright 2002-2015 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.
|
||||
@@ -247,6 +247,7 @@ public class JmsListenerAnnotationBeanPostProcessor
|
||||
endpoint.setBean(bean);
|
||||
endpoint.setMethod(method);
|
||||
endpoint.setMessageHandlerMethodFactory(this.messageHandlerMethodFactory);
|
||||
endpoint.setBeanFactory(this.beanFactory);
|
||||
endpoint.setId(getEndpointId(jmsListener));
|
||||
endpoint.setDestination(resolve(jmsListener.destination()));
|
||||
if (StringUtils.hasText(jmsListener.selector())) {
|
||||
|
||||
@@ -21,6 +21,8 @@ import java.util.Arrays;
|
||||
|
||||
import org.springframework.aop.framework.AopProxyUtils;
|
||||
import org.springframework.aop.support.AopUtils;
|
||||
import org.springframework.beans.factory.BeanFactory;
|
||||
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
|
||||
import org.springframework.core.annotation.AnnotationUtils;
|
||||
import org.springframework.jms.listener.MessageListenerContainer;
|
||||
import org.springframework.jms.listener.adapter.MessagingMessageListenerAdapter;
|
||||
@@ -46,6 +48,8 @@ public class MethodJmsListenerEndpoint extends AbstractJmsListenerEndpoint {
|
||||
|
||||
private MessageHandlerMethodFactory messageHandlerMethodFactory;
|
||||
|
||||
private BeanFactory beanFactory;
|
||||
|
||||
|
||||
/**
|
||||
* Set the object instance that should manage this endpoint.
|
||||
@@ -78,6 +82,12 @@ public class MethodJmsListenerEndpoint extends AbstractJmsListenerEndpoint {
|
||||
this.messageHandlerMethodFactory = messageHandlerMethodFactory;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the {@link BeanFactory} to use to resolve expressions (can be null).
|
||||
*/
|
||||
public void setBeanFactory(BeanFactory beanFactory) {
|
||||
this.beanFactory = beanFactory;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected MessagingMessageListenerAdapter createMessageListener(MessageListenerContainer container) {
|
||||
@@ -110,7 +120,10 @@ public class MethodJmsListenerEndpoint extends AbstractJmsListenerEndpoint {
|
||||
return new MessagingMessageListenerAdapter();
|
||||
}
|
||||
|
||||
private String getDefaultResponseDestination() {
|
||||
/**
|
||||
* Return the default response destination, if any.
|
||||
*/
|
||||
protected String getDefaultResponseDestination() {
|
||||
Method specificMethod = getMostSpecificMethod();
|
||||
SendTo ann = AnnotationUtils.getAnnotation(specificMethod, SendTo.class);
|
||||
if (ann != null) {
|
||||
@@ -119,11 +132,23 @@ public class MethodJmsListenerEndpoint extends AbstractJmsListenerEndpoint {
|
||||
throw new IllegalStateException("Invalid @" + SendTo.class.getSimpleName() + " annotation on '"
|
||||
+ specificMethod + "' one destination must be set (got " + Arrays.toString(destinations) + ")");
|
||||
}
|
||||
return (String) destinations[0];
|
||||
return resolve((String) destinations[0]);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Resolve the specified value if possible.
|
||||
* @see ConfigurableBeanFactory#resolveEmbeddedValue
|
||||
*/
|
||||
private String resolve(String value) {
|
||||
if (this.beanFactory instanceof ConfigurableBeanFactory) {
|
||||
return ((ConfigurableBeanFactory) this.beanFactory).resolveEmbeddedValue(value);
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
|
||||
private Method getMostSpecificMethod() {
|
||||
if (AopUtils.isAopProxy(this.bean)) {
|
||||
Class<?> target = AopProxyUtils.ultimateTargetClass(this.bean);
|
||||
|
||||
Reference in New Issue
Block a user