Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incorrect @JmsListener parameter matching when the listener is a JDK proxy [SPR-13576] #18153

Closed
spring-projects-issues opened this issue Oct 15, 2015 · 3 comments
Assignees
Labels
type: enhancement A general enhancement
Milestone

Comments

@spring-projects-issues
Copy link
Collaborator

spring-projects-issues commented Oct 15, 2015

Gary Russell opened SPR-13576 and commented

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).


Affects: 4.2.1

Issue Links:

Referenced from: commits da9c80c

@spring-projects-issues
Copy link
Collaborator Author

spring-projects-issues commented Oct 15, 2015

Gary Russell commented

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

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

@spring-projects-issues
Copy link
Collaborator Author

spring-projects-issues commented Oct 16, 2015

Stéphane Nicoll commented

Thanks for the follow-up Gary, much appreciated!

@spring-projects-issues
Copy link
Collaborator Author

spring-projects-issues commented Nov 9, 2015

Juergen Hoeller commented

Fixed for 4.2.3 now, along with #18230.

Juergen

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: enhancement A general enhancement
Projects
None yet
Development

No branches or pull requests

2 participants