From 045d280542923c3e8566ba5c0c677cb95d6e9650 Mon Sep 17 00:00:00 2001 From: Marius Bogoevici Date: Thu, 21 Apr 2016 09:17:38 -0400 Subject: [PATCH] Prevent eager initialization of the MessageHandlerMethodFactory Fixes #494 The eager initialization of the bean triggers the eager initialization of the ObjectMapper, which causes issues with HATEOAS and Hystrix. --- .../ChannelBindingServiceConfiguration.java | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/spring-cloud-stream/src/main/java/org/springframework/cloud/stream/config/ChannelBindingServiceConfiguration.java b/spring-cloud-stream/src/main/java/org/springframework/cloud/stream/config/ChannelBindingServiceConfiguration.java index 2751e49a4..efbf505cf 100644 --- a/spring-cloud-stream/src/main/java/org/springframework/cloud/stream/config/ChannelBindingServiceConfiguration.java +++ b/spring-cloud-stream/src/main/java/org/springframework/cloud/stream/config/ChannelBindingServiceConfiguration.java @@ -62,6 +62,7 @@ import org.springframework.messaging.MessageChannel; import org.springframework.messaging.core.DestinationResolutionException; import org.springframework.messaging.core.DestinationResolver; import org.springframework.messaging.handler.annotation.support.DefaultMessageHandlerMethodFactory; +import org.springframework.messaging.handler.annotation.support.MessageHandlerMethodFactory; import org.springframework.tuple.spel.TuplePropertyAccessor; import org.springframework.util.CollectionUtils; @@ -235,12 +236,17 @@ public class ChannelBindingServiceConfiguration { } @Bean - public static StreamListenerAnnotationBeanPostProcessor bindToAnnotationBeanPostProcessor( - @Lazy BinderAwareChannelResolver binderAwareChannelResolver, - @Lazy CompositeMessageConverterFactory compositeMessageConverterFactory) { + public static MessageHandlerMethodFactory messageHandlerMethodFactory(CompositeMessageConverterFactory compositeMessageConverterFactory) { DefaultMessageHandlerMethodFactory messageHandlerMethodFactory = new DefaultMessageHandlerMethodFactory(); messageHandlerMethodFactory.setMessageConverter(compositeMessageConverterFactory.getMessageConverterForAllRegistered()); - messageHandlerMethodFactory.afterPropertiesSet(); - return new StreamListenerAnnotationBeanPostProcessor(binderAwareChannelResolver, messageHandlerMethodFactory); + return messageHandlerMethodFactory; + } + + @Bean + public static StreamListenerAnnotationBeanPostProcessor bindToAnnotationBeanPostProcessor( + @Lazy BinderAwareChannelResolver binderAwareChannelResolver, + @Lazy MessageHandlerMethodFactory messageHandlerMethodFactory) { + return new StreamListenerAnnotationBeanPostProcessor(binderAwareChannelResolver, + messageHandlerMethodFactory); } }