diff --git a/spring-integration-core/src/main/java/org/springframework/integration/history/MessageHistoryWriter.java b/spring-integration-core/src/main/java/org/springframework/integration/history/MessageHistoryWriter.java index 3d089b589f..05c79d1e0f 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/history/MessageHistoryWriter.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/history/MessageHistoryWriter.java @@ -26,19 +26,31 @@ import org.springframework.integration.context.NamedComponent; import org.springframework.integration.core.Message; import org.springframework.integration.core.MessageChannel; import org.springframework.integration.message.MessageHandler; +import org.springframework.util.Assert; /** - * This components is responsible for maintaining the history of {@link MessageChannel}s and - * {@link MessageHandler}s - * There can only be ine instance of this class per ApplicationContext hierarchy - * otherwise the Exception will be thrown. + * This component is responsible for maintaining the history of {@link MessageChannel}s and + * {@link MessageHandler}s. There can only be one instance of this class per ApplicationContext + * hierarchy otherwise an Exception will be thrown. * * @author Oleg Zhurakousky * @since 2.0 */ public class MessageHistoryWriter implements BeanFactoryAware, InitializingBean{ - private BeanFactory beanFactory; + private volatile BeanFactory beanFactory; + + + public void setBeanFactory(BeanFactory beanFactory) throws BeansException { + this.beanFactory = beanFactory; + } + + public void afterPropertiesSet() throws Exception { + Assert.notNull(this.beanFactory, "BeanFactory is required"); + if (BeanFactoryUtils.beansOfTypeIncludingAncestors((ListableBeanFactory) this.beanFactory, MessageHistoryWriter.class).size() > 1) { + throw new IllegalArgumentException("more than one MessageHistoryWriter exists in the context"); + } + } public void writeHistory(NamedComponent component, Message message) { if (message != null) { @@ -46,14 +58,4 @@ public class MessageHistoryWriter implements BeanFactoryAware, InitializingBean{ } } - public void setBeanFactory(BeanFactory beanFactory) throws BeansException { - this.beanFactory = beanFactory; - } - - public void afterPropertiesSet() throws Exception { - if (BeanFactoryUtils.beansOfTypeIncludingAncestors((ListableBeanFactory)this.beanFactory, MessageHistoryWriter.class).size() > 1){ - throw new IllegalArgumentException("Attempt to register more then one MessageHistoryWriter"); - } - } - }