Skip to content

Commit d04f785

Browse files
committed
Introduced createMethodJmsListenerEndpoint template method
Issue: SPR-13774 (cherry picked from commit 9589749)
1 parent e37b75b commit d04f785

File tree

2 files changed

+22
-10
lines changed

2 files changed

+22
-10
lines changed

spring-jms/src/main/java/org/springframework/jms/annotation/JmsListenerAnnotationBeanPostProcessor.java

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ public void doWith(Method method) throws IllegalArgumentException, IllegalAccess
209209
if (annotatedMethods.isEmpty()) {
210210
this.nonAnnotatedClasses.add(bean.getClass());
211211
if (logger.isTraceEnabled()) {
212-
logger.trace("No @JmsListener annotations found on bean class: " + bean.getClass());
212+
logger.trace("No @JmsListener annotations found on bean type: " + bean.getClass());
213213
}
214214
}
215215
else {
@@ -243,7 +243,7 @@ protected void processJmsListener(JmsListener jmsListener, Method method, Object
243243
}
244244
}
245245

246-
MethodJmsListenerEndpoint endpoint = new MethodJmsListenerEndpoint();
246+
MethodJmsListenerEndpoint endpoint = createMethodJmsListenerEndpoint();
247247
endpoint.setBean(bean);
248248
endpoint.setMethod(method);
249249
endpoint.setMessageHandlerMethodFactory(this.messageHandlerMethodFactory);
@@ -267,15 +267,26 @@ protected void processJmsListener(JmsListener jmsListener, Method method, Object
267267
factory = this.beanFactory.getBean(containerFactoryBeanName, JmsListenerContainerFactory.class);
268268
}
269269
catch (NoSuchBeanDefinitionException ex) {
270-
throw new BeanInitializationException("Could not register jms listener endpoint on [" +
271-
method + "], no " + JmsListenerContainerFactory.class.getSimpleName() + " with id '" +
272-
containerFactoryBeanName + "' was found in the application context", ex);
270+
throw new BeanInitializationException("Could not register JMS listener endpoint on [" +
271+
method + "], no " + JmsListenerContainerFactory.class.getSimpleName() +
272+
" with id '" + containerFactoryBeanName + "' was found in the application context", ex);
273273
}
274274
}
275275

276276
this.registrar.registerEndpoint(endpoint, factory);
277277
}
278278

279+
/**
280+
* Instantiate an empty {@link MethodJmsListenerEndpoint} for further
281+
* configuration with provided parameters in {@link #processJmsListener}.
282+
* @return a new {@code MethodJmsListenerEndpoint} or subclass thereof
283+
* @since 4.1.9
284+
* @see MethodJmsListenerEndpoint#createMessageListenerInstance()
285+
*/
286+
protected MethodJmsListenerEndpoint createMethodJmsListenerEndpoint() {
287+
return new MethodJmsListenerEndpoint();
288+
}
289+
279290
private String getEndpointId(JmsListener jmsListener) {
280291
if (StringUtils.hasText(jmsListener.id())) {
281292
return resolve(jmsListener.id());

spring-jms/src/main/java/org/springframework/jms/config/MethodJmsListenerEndpoint.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2014 the original author or authors.
2+
* Copyright 2002-2015 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -49,7 +49,7 @@ public class MethodJmsListenerEndpoint extends AbstractJmsListenerEndpoint {
4949

5050

5151
/**
52-
* Set the object instance that should manage this endpoint.
52+
* Set the actual bean instance to invoke this endpoint method on.
5353
*/
5454
public void setBean(Object bean) {
5555
this.bean = bean;
@@ -60,7 +60,7 @@ public Object getBean() {
6060
}
6161

6262
/**
63-
* Set the method to invoke to process a message managed by this endpoint.
63+
* Set the method to invoke for processing a message managed by this endpoint.
6464
*/
6565
public void setMethod(Method method) {
6666
this.method = method;
@@ -110,6 +110,7 @@ protected MessagingMessageListenerAdapter createMessageListener(MessageListenerC
110110

111111
/**
112112
* Create an empty {@link MessagingMessageListenerAdapter} instance.
113+
* @return a new {@code MessagingMessageListenerAdapter} or subclass thereof
113114
*/
114115
protected MessagingMessageListenerAdapter createMessageListenerInstance() {
115116
return new MessagingMessageListenerAdapter();
@@ -121,8 +122,8 @@ private String getDefaultResponseDestination() {
121122
if (ann != null) {
122123
Object[] destinations = ann.value();
123124
if (destinations.length != 1) {
124-
throw new IllegalStateException("Invalid @" + SendTo.class.getSimpleName() + " annotation on '"
125-
+ specificMethod + "' one destination must be set (got " + Arrays.toString(destinations) + ")");
125+
throw new IllegalStateException("Invalid @" + SendTo.class.getSimpleName() + " annotation on '" +
126+
specificMethod + "' one destination must be set (got " + Arrays.toString(destinations) + ")");
126127
}
127128
return (String) destinations[0];
128129
}

0 commit comments

Comments
 (0)