From d04f785094f22ff1e1f796c7b6dd6b16b66b1724 Mon Sep 17 00:00:00 2001 From: Juergen Hoeller Date: Tue, 8 Dec 2015 17:07:40 +0100 Subject: [PATCH] Introduced createMethodJmsListenerEndpoint template method Issue: SPR-13774 (cherry picked from commit 9589749) --- ...msListenerAnnotationBeanPostProcessor.java | 21 ++++++++++++++----- .../jms/config/MethodJmsListenerEndpoint.java | 11 +++++----- 2 files changed, 22 insertions(+), 10 deletions(-) diff --git a/spring-jms/src/main/java/org/springframework/jms/annotation/JmsListenerAnnotationBeanPostProcessor.java b/spring-jms/src/main/java/org/springframework/jms/annotation/JmsListenerAnnotationBeanPostProcessor.java index 2aa44a5b06..d50b084899 100644 --- a/spring-jms/src/main/java/org/springframework/jms/annotation/JmsListenerAnnotationBeanPostProcessor.java +++ b/spring-jms/src/main/java/org/springframework/jms/annotation/JmsListenerAnnotationBeanPostProcessor.java @@ -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()); diff --git a/spring-jms/src/main/java/org/springframework/jms/config/MethodJmsListenerEndpoint.java b/spring-jms/src/main/java/org/springframework/jms/config/MethodJmsListenerEndpoint.java index a976d44394..7876c10974 100644 --- a/spring-jms/src/main/java/org/springframework/jms/config/MethodJmsListenerEndpoint.java +++ b/spring-jms/src/main/java/org/springframework/jms/config/MethodJmsListenerEndpoint.java @@ -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]; }