Skip to content

Commit 4b1274c

Browse files
artembilanspring-builds
authored andcommitted
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. (cherry picked from commit 60314fe)
1 parent 1bbde61 commit 4b1274c

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
@@ -23,7 +23,6 @@
2323
import java.util.concurrent.locks.ReentrantLock;
2424

2525
import org.springframework.beans.factory.BeanCreationException;
26-
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
2726
import org.springframework.core.task.SimpleAsyncTaskExecutor;
2827
import org.springframework.integration.handler.AbstractReplyProducingMessageHandler;
2928
import org.springframework.integration.support.management.ManageableLifecycle;
@@ -157,9 +156,12 @@ private void initialize() {
157156
this.gatewayProxyFactoryBean.setDefaultReplyTimeout(this.replyTimeout);
158157
}
159158

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

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)