16
16
17
17
package org .springframework .integration .dsl .context ;
18
18
19
- import java .util .Arrays ;
20
19
import java .util .Collections ;
21
20
import java .util .HashMap ;
22
21
import java .util .Map ;
@@ -77,6 +76,8 @@ public final class IntegrationFlowContext implements BeanFactoryAware {
77
76
78
77
private ConfigurableListableBeanFactory beanFactory ;
79
78
79
+ private BeanDefinitionRegistry beanDefinitionRegistry ;
80
+
80
81
private IntegrationFlowContext () {
81
82
}
82
83
@@ -87,6 +88,7 @@ public void setBeanFactory(BeanFactory beanFactory) throws BeansException {
87
88
"'ConfigurableListableBeanFactory'. " +
88
89
"Consider using 'GenericApplicationContext' implementation." );
89
90
this .beanFactory = (ConfigurableListableBeanFactory ) beanFactory ;
91
+ this .beanDefinitionRegistry = (BeanDefinitionRegistry ) this .beanFactory ;
90
92
}
91
93
92
94
/**
@@ -184,24 +186,29 @@ public void remove(String flowId) {
184
186
IntegrationFlowRegistration flowRegistration = this .registry .remove (flowId );
185
187
flowRegistration .stop ();
186
188
187
- BeanDefinitionRegistry beanDefinitionRegistry = (BeanDefinitionRegistry ) this .beanFactory ;
188
-
189
- Arrays .stream (this .beanFactory .getDependentBeans (flowId ))
190
- .forEach (beanName -> {
191
- beanDefinitionRegistry .removeBeanDefinition (beanName );
192
- // TODO until https://jira.spring.io/browse/SPR-16837
193
- Arrays .asList (beanDefinitionRegistry .getAliases (beanName ))
194
- .forEach (beanDefinitionRegistry ::removeAlias );
195
- });
189
+ removeDependantBeans (flowId );
196
190
197
- beanDefinitionRegistry .removeBeanDefinition (flowId );
191
+ this . beanDefinitionRegistry .removeBeanDefinition (flowId );
198
192
}
199
193
else {
200
194
throw new IllegalStateException ("An IntegrationFlow with the id "
201
195
+ "[" + flowId + "] doesn't exist in the registry." );
202
196
}
203
197
}
204
198
199
+ private void removeDependantBeans (String parentName ) {
200
+ String [] dependentBeans = this .beanFactory .getDependentBeans (parentName );
201
+ for (String beanName : dependentBeans ) {
202
+ removeDependantBeans (beanName );
203
+ this .beanDefinitionRegistry .removeBeanDefinition (beanName );
204
+ // TODO until https://jira.spring.io/browse/SPR-16837
205
+ String [] aliases = this .beanDefinitionRegistry .getAliases (beanName );
206
+ for (String alias : aliases ) {
207
+ this .beanDefinitionRegistry .removeAlias (alias );
208
+ }
209
+ }
210
+ }
211
+
205
212
/**
206
213
* Obtain a {@link MessagingTemplate} with its default destination set to the input channel
207
214
* of the {@link IntegrationFlow} for provided {@code flowId}.
@@ -249,7 +256,7 @@ private String generateBeanName(Object instance, String parentName) {
249
256
*/
250
257
public final class IntegrationFlowRegistrationBuilder {
251
258
252
- private Map <Object , String > additionalBeans = new HashMap <>();
259
+ private final Map <Object , String > additionalBeans = new HashMap <>();
253
260
254
261
private final IntegrationFlowRegistration integrationFlowRegistration ;
255
262
0 commit comments