Skip to content

Commit 60314fe

Browse files
authored
GH-10309: Don't register bean for internal GatewayMH.gatewayProxyFactoryBean (#10311)
Fixes: #10309 The call of the `BeanFactory.initializeBean()` on the internal `GatewayProxyFactoryBean` instance of the `GatewayMessageHandler` causes an extra bean to be processed everywhere. Since such a registration happens from the `GatewayMessageHandler.start()`, the `SpringIntegrationTestExecutionListener#prepareTestInstance` may suffer from a `ConcurrentModificationException` on the `autoStartupCandidates`. Just because its logic is to call `start()` from that `autoStartupCandidates` collection iteration. Essentially, we don't need that since a `GatewayMessageHandler` is a bean itself. The `GatewayProxyFactoryBean` is used internally to avoid logic duplication of the proxy creating on the provided interface. * Rework the logic of the `GatewayMessageHandler` to call all the respective `BeanFactory` call-backs manually. * Add an `IntegrationFlow` bean with a `gateway()` into the `MockMessageHandlerTests` to ensure that `SpringIntegrationTestExecutionListener` does not suffer from a `ConcurrentModificationException` anymore. **Auto-cherry-pick to `6.5.x`**
1 parent badacb1 commit 60314fe

File tree

2 files changed

+13
-4
lines changed

2 files changed

+13
-4
lines changed

spring-integration-core/src/main/java/org/springframework/integration/gateway/GatewayMessageHandler.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
import org.jspecify.annotations.Nullable;
2626

2727
import org.springframework.beans.factory.BeanCreationException;
28-
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
2928
import org.springframework.core.task.SimpleAsyncTaskExecutor;
3029
import org.springframework.integration.handler.AbstractReplyProducingMessageHandler;
3130
import org.springframework.integration.support.management.ManageableLifecycle;
@@ -158,9 +157,12 @@ private void initialize() {
158157
this.gatewayProxyFactoryBean.setDefaultReplyTimeout(this.replyTimeout);
159158
}
160159

161-
if (getBeanFactory() instanceof ConfigurableListableBeanFactory configurableListableBeanFactory) {
162-
configurableListableBeanFactory.initializeBean(this.gatewayProxyFactoryBean, getComponentName() + "#gpfb");
163-
}
160+
this.gatewayProxyFactoryBean.setBeanName(getComponentName() + "#gpfb");
161+
this.gatewayProxyFactoryBean.setBeanFactory(getBeanFactory());
162+
this.gatewayProxyFactoryBean.setApplicationContext(getApplicationContext());
163+
this.gatewayProxyFactoryBean.setBeanClassLoader(getBeanClassLoader());
164+
this.gatewayProxyFactoryBean.afterPropertiesSet();
165+
164166
try {
165167
this.exchanger = this.gatewayProxyFactoryBean.getObject();
166168
}

spring-integration-test/src/test/java/org/springframework/integration/test/mock/MockMessageHandlerTests.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
import org.springframework.integration.channel.DirectChannel;
3737
import org.springframework.integration.channel.QueueChannel;
3838
import org.springframework.integration.config.EnableIntegration;
39+
import org.springframework.integration.dsl.IntegrationFlow;
3940
import org.springframework.integration.endpoint.ReactiveStreamsConsumer;
4041
import org.springframework.integration.expression.ValueExpression;
4142
import org.springframework.integration.handler.ExpressionEvaluatingMessageHandler;
@@ -365,6 +366,12 @@ public ReactiveMessageHandler reactiveMessageHandler() {
365366
return message -> Mono.empty();
366367
}
367368

369+
// Before the fix for https://github.com/spring-projects/spring-integration/issues/10309 this test suite has failed
370+
@Bean
371+
IntegrationFlow flowWithGateway() {
372+
return flow -> flow.gateway(subFlow -> subFlow.bridge());
373+
}
374+
368375
}
369376

370377
}

0 commit comments

Comments
 (0)