Setting ChannelRegistry in MessageBusAwareBeanPostProcessor and avoiding potential NPE in ConcurrencyInterceptor (when ChannelRegistry has not been set).

This commit is contained in:
Mark Fisher
2008-07-07 11:58:12 +00:00
parent c0eecad7df
commit f8e7bdf3c2
2 changed files with 12 additions and 8 deletions

View File

@@ -18,6 +18,7 @@ package org.springframework.integration.bus;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.BeanPostProcessor;
import org.springframework.integration.channel.ChannelRegistryAware;
import org.springframework.util.Assert;
/**
@@ -25,7 +26,7 @@ import org.springframework.util.Assert;
* reference to the {@link MessageBus}.
*
* @author Marius Bogoevici
*
* @author Mark Fisher
*/
public class MessageBusAwareBeanPostProcessor implements BeanPostProcessor {
@@ -37,18 +38,21 @@ public class MessageBusAwareBeanPostProcessor implements BeanPostProcessor {
}
public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
if (bean instanceof MessageBusAware) {
((MessageBusAware) bean).setMessageBus(messageBus);
}
return bean;
return postProcessIfNecessary(bean);
}
public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException {
return postProcessIfNecessary(bean);
}
private Object postProcessIfNecessary(Object bean) {
if (bean instanceof MessageBusAware) {
((MessageBusAware) bean).setMessageBus(messageBus);
((MessageBusAware) bean).setMessageBus(this.messageBus);
}
if (bean instanceof ChannelRegistryAware) {
((ChannelRegistryAware) bean).setChannelRegistry(this.messageBus);
}
return bean;
}
}

View File

@@ -92,7 +92,7 @@ public class ConcurrencyInterceptor extends EndpointInterceptorAdapter
}
public void afterPropertiesSet() throws Exception {
if (this.errorHandler == null) {
if (this.errorHandler == null && this.channelRegistry != null) {
MessageChannel errorChannel = this.channelRegistry.lookupChannel(
ChannelRegistry.ERROR_CHANNEL_NAME);
if (errorChannel != null) {