From 9b787a0d5a29b469cae44361dd699404f647a732 Mon Sep 17 00:00:00 2001 From: Mark Fisher Date: Sat, 5 Jul 2008 22:26:11 +0000 Subject: [PATCH] MessageBus now does a second pass to pick up any MessageChannel that has been provided between the setApplicationContext callback and the ContextRefreshedEvent (INT-270). --- .../springframework/integration/bus/MessageBus.java | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/org.springframework.integration/src/main/java/org/springframework/integration/bus/MessageBus.java b/org.springframework.integration/src/main/java/org/springframework/integration/bus/MessageBus.java index 6a4e83e606..d65a5cc31c 100644 --- a/org.springframework.integration/src/main/java/org/springframework/integration/bus/MessageBus.java +++ b/org.springframework.integration/src/main/java/org/springframework/integration/bus/MessageBus.java @@ -173,7 +173,15 @@ public class MessageBus implements ChannelRegistry, EndpointRegistry, Map channelBeans = (Map) context .getBeansOfType(MessageChannel.class); for (Map.Entry entry : channelBeans.entrySet()) { - this.registerChannel(entry.getKey(), entry.getValue()); + String channelName = entry.getKey(); + MessageChannel previousChannel = this.lookupChannel(channelName); + if (previousChannel == null) { + this.registerChannel(channelName, entry.getValue()); + } + else if (!previousChannel.equals(entry.getValue())) { + throw new ConfigurationException("A different channel instance has already " + + "been registered with the name '" + channelName + "'."); + } } } @@ -455,6 +463,7 @@ public class MessageBus implements ChannelRegistry, EndpointRegistry, public void onApplicationEvent(ApplicationEvent event) { if (event instanceof ContextRefreshedEvent) { ApplicationContext context = ((ContextRefreshedEvent) event).getApplicationContext(); + this.registerChannels(context); this.registerEndpoints(context); this.registerGateways(context); if (this.configureAsyncEventMulticaster) {