diff --git a/org.springframework.integration/src/main/java/org/springframework/integration/channel/MessagePublishingErrorHandler.java b/org.springframework.integration/src/main/java/org/springframework/integration/channel/MessagePublishingErrorHandler.java index 024cc9f2bb..4b0ef49903 100644 --- a/org.springframework.integration/src/main/java/org/springframework/integration/channel/MessagePublishingErrorHandler.java +++ b/org.springframework.integration/src/main/java/org/springframework/integration/channel/MessagePublishingErrorHandler.java @@ -19,6 +19,8 @@ package org.springframework.integration.channel; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.springframework.beans.factory.BeanFactory; +import org.springframework.beans.factory.BeanFactoryAware; import org.springframework.integration.core.Message; import org.springframework.integration.core.MessageChannel; import org.springframework.integration.core.MessagingException; @@ -32,17 +34,20 @@ import org.springframework.util.Assert; * * @author Mark Fisher */ -public class MessagePublishingErrorHandler implements ErrorHandler { +public class MessagePublishingErrorHandler implements ErrorHandler, BeanFactoryAware { private final Log logger = LogFactory.getLog(this.getClass()); - private final ChannelResolver channelResolver; + private volatile ChannelResolver channelResolver; private volatile MessageChannel defaultErrorChannel; private volatile long sendTimeout = 1000; + public MessagePublishingErrorHandler() { + } + public MessagePublishingErrorHandler(ChannelResolver channelResolver) { Assert.notNull(channelResolver, "channelResolver must not be null"); this.channelResolver = channelResolver; @@ -57,6 +62,13 @@ public class MessagePublishingErrorHandler implements ErrorHandler { this.sendTimeout = sendTimeout; } + public void setBeanFactory(BeanFactory beanFactory) { + Assert.notNull(beanFactory, "beanFactory must not be null"); + if (this.channelResolver == null) { + this.channelResolver = new BeanFactoryChannelResolver(beanFactory); + } + } + public final void handle(Throwable t) { Message failedMessage = (t instanceof MessagingException) ? ((MessagingException) t).getFailedMessage() : null;