Skip to content

Commit 0461167

Browse files
committed
Fix concurrency for StandardIntegrationFlowContext
If we don't get access to `BeanFactory` in exclusive mode, the `getBean(Class<?>)` may fail with a `BeanCurrentlyInCreationException` when we register several `IntegrationFlow` instances in parallel
1 parent 13a113c commit 0461167

File tree

1 file changed

+3
-8
lines changed

1 file changed

+3
-8
lines changed

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

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2016-2023 the original author or authors.
2+
* Copyright 2016-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.
@@ -95,11 +95,9 @@ public boolean isUseIdAsPrefix(String flowId) {
9595
private IntegrationFlowRegistration register(StandardIntegrationFlowRegistrationBuilder builder) {
9696
IntegrationFlow integrationFlow = builder.integrationFlow;
9797
String flowId = builder.id;
98-
Lock registerBeanLock = null;
98+
this.registerFlowsLock.lock();
9999
try {
100100
if (flowId == null) {
101-
registerBeanLock = this.registerFlowsLock;
102-
registerBeanLock.lock();
103101
flowId = generateBeanName(integrationFlow, null);
104102
builder.id(flowId);
105103
}
@@ -112,9 +110,7 @@ else if (this.registry.containsKey(flowId)) {
112110
integrationFlow = registerFlowBean(integrationFlow, flowId, builder.source);
113111
}
114112
finally {
115-
if (registerBeanLock != null) {
116-
registerBeanLock.unlock();
117-
}
113+
this.registerFlowsLock.unlock();
118114
}
119115

120116
builder.integrationFlow = integrationFlow;
@@ -209,7 +205,6 @@ private void removeDependantBeans(String parentName) {
209205
for (String beanName : dependentBeans) {
210206
removeDependantBeans(beanName);
211207
this.beanDefinitionRegistry.removeBeanDefinition(beanName);
212-
// TODO until https://jira.spring.io/browse/SPR-16837
213208
String[] aliases = this.beanDefinitionRegistry.getAliases(beanName);
214209
for (String alias : aliases) {
215210
this.beanDefinitionRegistry.removeAlias(alias);

0 commit comments

Comments
 (0)