Introduced createMethodJmsListenerEndpoint template method

Issue: SPR-13774
(cherry picked from commit 9589749)
This commit is contained in:
Juergen Hoeller
2015-12-08 17:07:40 +01:00
parent e37b75b165
commit d04f785094
2 changed files with 22 additions and 10 deletions

View File

@@ -209,7 +209,7 @@ public class JmsListenerAnnotationBeanPostProcessor
if (annotatedMethods.isEmpty()) {
this.nonAnnotatedClasses.add(bean.getClass());
if (logger.isTraceEnabled()) {
logger.trace("No @JmsListener annotations found on bean class: " + bean.getClass());
logger.trace("No @JmsListener annotations found on bean type: " + bean.getClass());
}
}
else {
@@ -243,7 +243,7 @@ public class JmsListenerAnnotationBeanPostProcessor
}
}
MethodJmsListenerEndpoint endpoint = new MethodJmsListenerEndpoint();
MethodJmsListenerEndpoint endpoint = createMethodJmsListenerEndpoint();
endpoint.setBean(bean);
endpoint.setMethod(method);
endpoint.setMessageHandlerMethodFactory(this.messageHandlerMethodFactory);
@@ -267,15 +267,26 @@ public class JmsListenerAnnotationBeanPostProcessor
factory = this.beanFactory.getBean(containerFactoryBeanName, JmsListenerContainerFactory.class);
}
catch (NoSuchBeanDefinitionException ex) {
throw new BeanInitializationException("Could not register jms listener endpoint on [" +
method + "], no " + JmsListenerContainerFactory.class.getSimpleName() + " with id '" +
containerFactoryBeanName + "' was found in the application context", ex);
throw new BeanInitializationException("Could not register JMS listener endpoint on [" +
method + "], no " + JmsListenerContainerFactory.class.getSimpleName() +
" with id '" + containerFactoryBeanName + "' was found in the application context", ex);
}
}
this.registrar.registerEndpoint(endpoint, factory);
}
/**
* Instantiate an empty {@link MethodJmsListenerEndpoint} for further
* configuration with provided parameters in {@link #processJmsListener}.
* @return a new {@code MethodJmsListenerEndpoint} or subclass thereof
* @since 4.1.9
* @see MethodJmsListenerEndpoint#createMessageListenerInstance()
*/
protected MethodJmsListenerEndpoint createMethodJmsListenerEndpoint() {
return new MethodJmsListenerEndpoint();
}
private String getEndpointId(JmsListener jmsListener) {
if (StringUtils.hasText(jmsListener.id())) {
return resolve(jmsListener.id());

View File

@@ -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.
@@ -49,7 +49,7 @@ public class MethodJmsListenerEndpoint extends AbstractJmsListenerEndpoint {
/**
* Set the object instance that should manage this endpoint.
* Set the actual bean instance to invoke this endpoint method on.
*/
public void setBean(Object bean) {
this.bean = bean;
@@ -60,7 +60,7 @@ public class MethodJmsListenerEndpoint extends AbstractJmsListenerEndpoint {
}
/**
* Set the method to invoke to process a message managed by this endpoint.
* Set the method to invoke for processing a message managed by this endpoint.
*/
public void setMethod(Method method) {
this.method = method;
@@ -110,6 +110,7 @@ public class MethodJmsListenerEndpoint extends AbstractJmsListenerEndpoint {
/**
* Create an empty {@link MessagingMessageListenerAdapter} instance.
* @return a new {@code MessagingMessageListenerAdapter} or subclass thereof
*/
protected MessagingMessageListenerAdapter createMessageListenerInstance() {
return new MessagingMessageListenerAdapter();
@@ -121,8 +122,8 @@ public class MethodJmsListenerEndpoint extends AbstractJmsListenerEndpoint {
if (ann != null) {
Object[] destinations = ann.value();
if (destinations.length != 1) {
throw new IllegalStateException("Invalid @" + SendTo.class.getSimpleName() + " annotation on '"
+ specificMethod + "' one destination must be set (got " + Arrays.toString(destinations) + ")");
throw new IllegalStateException("Invalid @" + SendTo.class.getSimpleName() + " annotation on '" +
specificMethod + "' one destination must be set (got " + Arrays.toString(destinations) + ")");
}
return (String) destinations[0];
}