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) {