Uploaded image for project: 'Spring Framework'
  1. Spring Framework
  2. SPR-13576

Incorrect @JmsListener parameter matching when the listener is a JDK proxy

    Details

    • Type: Improvement
    • Status: Closed
    • Priority: Major
    • Resolution: Complete
    • Affects Version/s: 4.2.1
    • Fix Version/s: 4.2.3
    • Component/s: None
    • Labels:
      None
    • Last commented by a User:
      false

      Description

      See AMQP-541 - a similar situation to that with the RabbitListener exists with JmsListener.

      @SpringBootApplication
      @EnableTransactionManagement
      public class JmsdemoApplication {
       
      	public static void main(String[] args) throws Exception {
      		ConfigurableApplicationContext ctx = SpringApplication.run(JmsdemoApplication.class, args);
      		JmsTemplate template = ctx.getBean(JmsTemplate.class);
      		template.convertAndSend("foo", "bar", new MessagePostProcessor() {
       
      			@Override
      			public Message postProcessMessage(Message message) throws JMSException {
      				message.setJMSCorrelationID("abc");
      				return message;
      			}
      		});
      		Thread.sleep(5000);
      		ctx.close();
      	}
       
      	@Bean
      	public Listener listener() {
      		return new ListenerImpl();
      	}
       
      	public interface Listener {
       
      		public void listen(String payload, @Header("jms_correlationId") String correlationId);
       
      	}
       
      	@Transactional
      	public static class ListenerImpl implements Listener {
       
      		@Override
      		@JmsListener(destination="foo")
      		public void listen(String payload, @Header("jms_correlationId") String correlationId) {
      			System.out.println(payload + ":" + correlationId);
      		}
       
      	}
       
      	@Bean
      	public PlatformTransactionManager transactionManager() {
      		return mock(PlatformTransactionManager.class);
      	}
       
      }
      

      Without @EnableTransactionManagement output is bar:abc as expected; when the listener is proxied, we get bar:bar.

      The problem is that the method in the InvocableHandlerMethod is the method on the proxy.

      With Spring Web, the method is the interface method.

      See the discussion on AMQP-541 and its PR for the suggested solution over there (discover the correct interface method to be consistent with Spring Web).

        Issue Links

          Activity

          Hide
          grussell Gary Russell added a comment -

          Spring Web uses HandlerMethodSelector.selectMethods() to iterate over the implemented interfaces looking for matches...

          		handlerTypes.addAll(Arrays.asList(handlerType.getInterfaces()));
          		for (Class<?> currentHandlerType : handlerTypes) {
                              ...
          

          Show
          grussell Gary Russell added a comment - Spring Web uses HandlerMethodSelector.selectMethods() to iterate over the implemented interfaces looking for matches... handlerTypes.addAll(Arrays.asList(handlerType.getInterfaces())); for (Class<?> currentHandlerType : handlerTypes) { ...
          Hide
          snicoll Stéphane Nicoll added a comment -

          Thanks for the follow-up Gary, much appreciated!

          Show
          snicoll Stéphane Nicoll added a comment - Thanks for the follow-up Gary, much appreciated!
          Hide
          juergen.hoeller Juergen Hoeller added a comment -

          Fixed for 4.2.3 now, along with SPR-13654.

          Juergen

          Show
          juergen.hoeller Juergen Hoeller added a comment - Fixed for 4.2.3 now, along with SPR-13654 . Juergen

            People

            • Assignee:
              juergen.hoeller Juergen Hoeller
              Reporter:
              grussell Gary Russell
              Last updater:
              Stéphane Nicoll
            • Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:
                Days since last comment:
                2 years, 15 weeks, 5 days ago