polishing BinderAwareRouterBeanPostProcessor

- removed BeanPostProcessor from BinderAwareRouterBeanPostProcessor
- simplified BinderAwareRouterBeanPostProcessor configuration in BindingServiceConfiguration

Resolves #1171
Resolves #1170
This commit is contained in:
Oleg Zhurakousky
2018-01-03 21:05:00 -05:00
parent 502bddd4e9
commit 87bf2734e7
2 changed files with 19 additions and 38 deletions

View File

@@ -16,7 +16,6 @@
package org.springframework.cloud.stream.binding;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.BeanPostProcessor;
import org.springframework.integration.router.AbstractMappingMessageRouter;
import org.springframework.messaging.MessageChannel;
@@ -28,21 +27,19 @@ import org.springframework.messaging.core.DestinationResolver;
*
* @author Mark Fisher
* @author Gary Russell
* @author Oleg Zhurakousky
*
* @deprecated as of 2.0, will be renamed/replaced as it is no longer a BPP and naming is a bit confusing
*/
public class BinderAwareRouterBeanPostProcessor implements BeanPostProcessor {
@Deprecated
public class BinderAwareRouterBeanPostProcessor {
private final DestinationResolver<MessageChannel> channelResolver;
public BinderAwareRouterBeanPostProcessor(DestinationResolver<MessageChannel> channelResolver) {
this.channelResolver = channelResolver;
}
@Override
public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
if (bean instanceof AbstractMappingMessageRouter) {
((AbstractMappingMessageRouter) bean).setChannelResolver(this.channelResolver);
public BinderAwareRouterBeanPostProcessor(AbstractMappingMessageRouter[] routers, DestinationResolver<MessageChannel> channelResolver) {
if (routers != null) {
for (AbstractMappingMessageRouter router : routers) {
router.setChannelResolver(channelResolver);
}
}
return bean;
}
}

View File

@@ -25,6 +25,7 @@ import org.springframework.beans.BeansException;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.BeanFactoryAware;
import org.springframework.beans.factory.SmartInitializingSingleton;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.beans.factory.config.BeanPostProcessor;
@@ -62,10 +63,10 @@ import org.springframework.integration.context.IntegrationContextUtils;
import org.springframework.integration.handler.AbstractReplyProducingMessageHandler;
import org.springframework.integration.handler.BridgeHandler;
import org.springframework.integration.json.JsonPropertyAccessor;
import org.springframework.integration.router.AbstractMappingMessageRouter;
import org.springframework.lang.Nullable;
import org.springframework.messaging.MessageChannel;
import org.springframework.messaging.SubscribableChannel;
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;
@@ -212,6 +213,13 @@ public class BindingServiceConfiguration {
return new ChannelBindingServiceProperties(bindingServiceProperties);
}
@Bean
@ConditionalOnMissingBean
public BinderAwareRouterBeanPostProcessor binderAwareRouterBeanPostProcessor(@Autowired(required=false) AbstractMappingMessageRouter[] routers,
@Autowired(required=false)DestinationResolver<MessageChannel> channelResolver) {
return new BinderAwareRouterBeanPostProcessor(routers, channelResolver);
}
// IMPORTANT: Nested class to avoid instantiating all of the above early
@Configuration
protected static class PostProcessorConfiguration {
@@ -241,33 +249,9 @@ public class BindingServiceConfiguration {
return bean;
}
@Override
public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
return bean;
}
};
}
@Bean
@ConditionalOnMissingBean(BinderAwareRouterBeanPostProcessor.class)
public static BinderAwareRouterBeanPostProcessor binderAwareRouterBeanPostProcessor(BeanFactory beanFactory) {
// IMPORTANT: Lazy delegate to avoid instantiating all of the above early
return new BinderAwareRouterBeanPostProcessor(new DestinationResolver<MessageChannel>() {
private BinderAwareChannelResolver binderAwareChannelResolver;
@Override
public MessageChannel resolveDestination(String name) throws DestinationResolutionException {
if (this.binderAwareChannelResolver == null) {
this.binderAwareChannelResolver = beanFactory.getBean(BinderAwareChannelResolver.class);
}
return this.binderAwareChannelResolver.resolveDestination(name);
}
});
}
@Bean
public static BeanPostProcessor messageHandlerHeaderPropagationBeanPostProcessor() {
return new NotPropagatedHeadersBeanPostProcessor();