AMQP-818: Fix Class-level listener properties

JIRA: https://jira.spring.io/browse/AMQP-818

`errorHandler` and `returnExceptions` properties were not injected into class-level listeners.

**cherry-pick to 2.0.x**
This commit is contained in:
Gary Russell
2018-06-04 10:41:17 -04:00
committed by Artem Bilan
parent 8d41b89216
commit efdc554b74
2 changed files with 13 additions and 10 deletions

View File

@@ -356,7 +356,6 @@ public class RabbitListenerAnnotationBeanPostProcessor
for (RabbitListener classLevelListener : classLevelListeners) {
MultiMethodRabbitListenerEndpoint endpoint =
new MultiMethodRabbitListenerEndpoint(checkedMethods, defaultMethod, bean);
endpoint.setBeanFactory(this.beanFactory);
processListener(endpoint, classLevelListener, bean, bean.getClass(), beanName);
}
}
@@ -365,12 +364,6 @@ public class RabbitListenerAnnotationBeanPostProcessor
Method methodToUse = checkProxy(method, bean);
MethodRabbitListenerEndpoint endpoint = new MethodRabbitListenerEndpoint();
endpoint.setMethod(methodToUse);
endpoint.setBeanFactory(this.beanFactory);
endpoint.setReturnExceptions(resolveExpressionAsBoolean(rabbitListener.returnExceptions()));
String errorHandlerBeanName = resolveExpressionAsString(rabbitListener.errorHandler(), "errorHandler");
if (StringUtils.hasText(errorHandlerBeanName)) {
endpoint.setErrorHandler(this.beanFactory.getBean(errorHandlerBeanName, RabbitListenerErrorHandler.class));
}
processListener(endpoint, rabbitListener, bean, methodToUse, beanName);
}
@@ -412,6 +405,12 @@ public class RabbitListenerAnnotationBeanPostProcessor
endpoint.setId(getEndpointId(rabbitListener));
endpoint.setQueueNames(resolveQueues(rabbitListener));
endpoint.setConcurrency(resolveExpressionAsStringOrInteger(rabbitListener.concurrency(), "concurrency"));
endpoint.setBeanFactory(this.beanFactory);
endpoint.setReturnExceptions(resolveExpressionAsBoolean(rabbitListener.returnExceptions()));
String errorHandlerBeanName = resolveExpressionAsString(rabbitListener.errorHandler(), "errorHandler");
if (StringUtils.hasText(errorHandlerBeanName)) {
endpoint.setErrorHandler(this.beanFactory.getBean(errorHandlerBeanName, RabbitListenerErrorHandler.class));
}
String group = rabbitListener.group();
if (StringUtils.hasText(group)) {
Object resolvedGroup = resolveExpression(group);

View File

@@ -21,6 +21,7 @@ import static org.hamcrest.Matchers.contains;
import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.instanceOf;
import static org.hamcrest.Matchers.notNullValue;
import static org.hamcrest.Matchers.startsWith;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
@@ -360,8 +361,10 @@ public class EnableRabbitIntegrationTests {
this.jsonRabbitTemplate.convertAndSend(exchange, routingKey, bar);
this.jsonRabbitTemplate.setReceiveTimeout(10000);
assertEquals("BAR: barMultiListenerJsonBean", this.jsonRabbitTemplate.receiveAndConvert("sendTo.replies.spel"));
assertThat(TestUtils.getPropertyValue(this.registry.getListenerContainer("multi"), "concurrentConsumers"),
equalTo(1));
MessageListenerContainer container = this.registry.getListenerContainer("multi");
assertThat(TestUtils.getPropertyValue(container, "concurrentConsumers"), equalTo(1));
assertThat(TestUtils.getPropertyValue(container, "messageListener.errorHandler"), notNullValue());
assertTrue(TestUtils.getPropertyValue(container, "messageListener.returnExceptions", Boolean.class));
}
@Test
@@ -1413,7 +1416,8 @@ public class EnableRabbitIntegrationTests {
@RabbitListener(id = "multi", bindings = @QueueBinding
(value = @Queue,
exchange = @Exchange(value = "multi.json.exch", autoDelete = "true"),
key = "multi.json.rk"), containerFactory = "simpleJsonListenerContainerFactory")
key = "multi.json.rk"), containerFactory = "simpleJsonListenerContainerFactory",
errorHandler = "alwaysBARHandler", returnExceptions = "true")
static class MultiListenerJsonBean {
@RabbitHandler