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
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2016-2023 the original author or authors.
|
||||
* Copyright 2016-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.
|
||||
@@ -95,11 +95,9 @@ public final class StandardIntegrationFlowContext implements IntegrationFlowCont
|
||||
private IntegrationFlowRegistration register(StandardIntegrationFlowRegistrationBuilder builder) {
|
||||
IntegrationFlow integrationFlow = builder.integrationFlow;
|
||||
String flowId = builder.id;
|
||||
Lock registerBeanLock = null;
|
||||
this.registerFlowsLock.lock();
|
||||
try {
|
||||
if (flowId == null) {
|
||||
registerBeanLock = this.registerFlowsLock;
|
||||
registerBeanLock.lock();
|
||||
flowId = generateBeanName(integrationFlow, null);
|
||||
builder.id(flowId);
|
||||
}
|
||||
@@ -112,9 +110,7 @@ public final class StandardIntegrationFlowContext implements IntegrationFlowCont
|
||||
integrationFlow = registerFlowBean(integrationFlow, flowId, builder.source);
|
||||
}
|
||||
finally {
|
||||
if (registerBeanLock != null) {
|
||||
registerBeanLock.unlock();
|
||||
}
|
||||
this.registerFlowsLock.unlock();
|
||||
}
|
||||
|
||||
builder.integrationFlow = integrationFlow;
|
||||
@@ -209,7 +205,6 @@ public final class StandardIntegrationFlowContext implements IntegrationFlowCont
|
||||
for (String beanName : dependentBeans) {
|
||||
removeDependantBeans(beanName);
|
||||
this.beanDefinitionRegistry.removeBeanDefinition(beanName);
|
||||
// TODO until https://jira.spring.io/browse/SPR-16837
|
||||
String[] aliases = this.beanDefinitionRegistry.getAliases(beanName);
|
||||
for (String alias : aliases) {
|
||||
this.beanDefinitionRegistry.removeAlias(alias);
|
||||
|
||||
Reference in New Issue
Block a user