Skip to content

Commit d8fb023

Browse files
committed
GH-9709: Fix IntegrationFlow for input channel resolution
Fixes: #9709 Issue link: #9709 The Java DSL loses an `inputChannel` when existing channel is referenced by its name. Then the target IntegrationFlow does not contain a bean reference for this channel and when we call its `getInputChannel()` we got something from middle of the flow. However, that `inputChannel` is really expected to be an input for the flow. * Fix `IntegrationFlowBeanPostProcessor` to get a bean by `MessageChannelReference` and populate it into `targetIntegrationComponents` as we do for newly created `DirectChannel` if there is no bean for provided `MessageChannelReference` # Conflicts: # spring-integration-core/src/main/java/org/springframework/integration/dsl/context/IntegrationFlowBeanPostProcessor.java
1 parent 1071c3c commit d8fb023

File tree

2 files changed

+17
-6
lines changed

2 files changed

+17
-6
lines changed

spring-integration-core/src/main/java/org/springframework/integration/dsl/context/IntegrationFlowBeanPostProcessor.java

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@
7474
import org.springframework.integration.gateway.AnnotationGatewayProxyFactoryBean;
7575
import org.springframework.integration.support.context.NamedComponent;
7676
import org.springframework.lang.Nullable;
77+
import org.springframework.messaging.MessageChannel;
7778
import org.springframework.messaging.MessageHandler;
7879
import org.springframework.util.Assert;
7980
import org.springframework.util.CollectionUtils;
@@ -181,11 +182,15 @@ else if (useFlowIdAsPrefix) {
181182
}
182183
else if (component instanceof MessageChannelReference messageChannelReference) {
183184
String channelBeanName = messageChannelReference.name();
185+
MessageChannel channelByName;
184186
if (!this.beanFactory.containsBean(channelBeanName)) {
185-
DirectChannel directChannel = new DirectChannel();
186-
registerComponent(directChannel, channelBeanName, flowBeanName);
187-
targetIntegrationComponents.put(directChannel, channelBeanName);
187+
channelByName = new DirectChannel();
188+
registerComponent(channelByName, channelBeanName, flowBeanName);
188189
}
190+
else {
191+
channelByName = this.beanFactory.getBean(channelBeanName, MessageChannel.class);
192+
}
193+
targetIntegrationComponents.put(channelByName, channelBeanName);
189194
}
190195
else if (component instanceof SourcePollingChannelAdapterSpec spec) {
191196
Map<Object, String> componentsToRegister = spec.getComponentsToRegister();

spring-integration-core/src/test/java/org/springframework/integration/dsl/composition/IntegrationFlowCompositionTests.java

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2021-2023 the original author or authors.
2+
* Copyright 2021-2024 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -202,11 +202,17 @@ IntegrationFlow middleFlow(IntegrationFlow firstFlow, IntegrationFlow lastFlow)
202202
.to(lastFlow);
203203
}
204204

205+
@Bean
206+
DirectChannel lastFlowInput() {
207+
return new DirectChannel();
208+
}
209+
205210
@Bean
206211
IntegrationFlow lastFlow() {
207-
return f -> f
212+
return IntegrationFlow.from("lastFlowInput")
208213
.<String, String>transform(p -> p + ", and last flow")
209-
.channel(c -> c.queue("lastFlowResult"));
214+
.channel(c -> c.queue("lastFlowResult"))
215+
.get();
210216
}
211217

212218
}

0 commit comments

Comments
 (0)