diff --git a/spring-integration-core/src/main/java/org/springframework/integration/dsl/context/IntegrationFlowBeanPostProcessor.java b/spring-integration-core/src/main/java/org/springframework/integration/dsl/context/IntegrationFlowBeanPostProcessor.java index b746627c83..3386fe7392 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/dsl/context/IntegrationFlowBeanPostProcessor.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/dsl/context/IntegrationFlowBeanPostProcessor.java @@ -74,6 +74,7 @@ import org.springframework.integration.dsl.support.MessageChannelReference; import org.springframework.integration.gateway.AnnotationGatewayProxyFactoryBean; import org.springframework.integration.support.context.NamedComponent; import org.springframework.lang.Nullable; +import org.springframework.messaging.MessageChannel; import org.springframework.messaging.MessageHandler; import org.springframework.util.Assert; import org.springframework.util.CollectionUtils; @@ -181,11 +182,15 @@ public class IntegrationFlowBeanPostProcessor } else if (component instanceof MessageChannelReference messageChannelReference) { String channelBeanName = messageChannelReference.name(); + MessageChannel channelByName; if (!this.beanFactory.containsBean(channelBeanName)) { - DirectChannel directChannel = new DirectChannel(); - registerComponent(directChannel, channelBeanName, flowBeanName); - targetIntegrationComponents.put(directChannel, channelBeanName); + channelByName = new DirectChannel(); + registerComponent(channelByName, channelBeanName, flowBeanName); } + else { + channelByName = this.beanFactory.getBean(channelBeanName, MessageChannel.class); + } + targetIntegrationComponents.put(channelByName, channelBeanName); } else if (component instanceof SourcePollingChannelAdapterSpec spec) { Map componentsToRegister = spec.getComponentsToRegister(); diff --git a/spring-integration-core/src/test/java/org/springframework/integration/dsl/composition/IntegrationFlowCompositionTests.java b/spring-integration-core/src/test/java/org/springframework/integration/dsl/composition/IntegrationFlowCompositionTests.java index d3413cacf1..ee84fef3ae 100644 --- a/spring-integration-core/src/test/java/org/springframework/integration/dsl/composition/IntegrationFlowCompositionTests.java +++ b/spring-integration-core/src/test/java/org/springframework/integration/dsl/composition/IntegrationFlowCompositionTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2021-2023 the original author or authors. + * Copyright 2021-2024 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -202,11 +202,17 @@ public class IntegrationFlowCompositionTests { .to(lastFlow); } + @Bean + DirectChannel lastFlowInput() { + return new DirectChannel(); + } + @Bean IntegrationFlow lastFlow() { - return f -> f + return IntegrationFlow.from("lastFlowInput") .transform(p -> p + ", and last flow") - .channel(c -> c.queue("lastFlowResult")); + .channel(c -> c.queue("lastFlowResult")) + .get(); } }