From d5303ca4f3b8d3fca24e8969fcd92fbca7c632fb Mon Sep 17 00:00:00 2001 From: Artem Bilan Date: Fri, 23 Feb 2018 14:40:07 -0500 Subject: [PATCH] INT-4413: Don't register flow under the same id JIRA: https://jira.spring.io/browse/INT-4413 When we override entity in the `IntegrationFlowContext.registry`, we may get dangling beans in the application context, when the structure of a new `IntegrationFlow` is different. * Fix `IntegrationFlowContext` to disallow to override the flow registration under the same name * Add JavaDocs to the `IntegrationFlowRegistrationBuilder` methods * Add `toString()` to the `IntegrationFlowRegistration` and `StandardIntegrationFlow` to make the logging of these components friendlier --- .../dsl/StandardIntegrationFlow.java | 10 ++-- .../dsl/context/IntegrationFlowContext.java | 48 +++++++++++++++++-- .../context/IntegrationFlowRegistration.java | 10 +++- .../dsl/manualflow/ManualFlowTests.java | 27 +++++++++++ 4 files changed, 87 insertions(+), 8 deletions(-) diff --git a/spring-integration-core/src/main/java/org/springframework/integration/dsl/StandardIntegrationFlow.java b/spring-integration-core/src/main/java/org/springframework/integration/dsl/StandardIntegrationFlow.java index d657de9740..945168a99a 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/dsl/StandardIntegrationFlow.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/dsl/StandardIntegrationFlow.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2017 the original author or authors. + * Copyright 2016-2018 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. @@ -44,7 +44,7 @@ import org.springframework.context.SmartLifecycle; * However, when we register an {@link IntegrationFlow} dynamically using the * {@link org.springframework.integration.dsl.context.IntegrationFlowContext} API, * the lifecycle processor from the application context is not involved; - * therefore we should control the lifecyle of the beans manually, or rely on the + * therefore we should control the lifecycle of the beans manually, or rely on the * {@link org.springframework.integration.dsl.context.IntegrationFlowContext} API. * Its created registration is {@code autoStartup} by default and * starts the flow when it is registered. If you disable the registration's auto- @@ -146,6 +146,11 @@ public class StandardIntegrationFlow implements IntegrationFlow, SmartLifecycle return 0; } + @Override + public String toString() { + return "StandardIntegrationFlow{integrationComponents=" + this.integrationComponents + '}'; + } + private static final class AggregatingCallback implements Runnable { private final AtomicInteger count; @@ -166,5 +171,4 @@ public class StandardIntegrationFlow implements IntegrationFlow, SmartLifecycle } - } diff --git a/spring-integration-core/src/main/java/org/springframework/integration/dsl/context/IntegrationFlowContext.java b/spring-integration-core/src/main/java/org/springframework/integration/dsl/context/IntegrationFlowContext.java index 57cc104a6b..4cba85a25f 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/dsl/context/IntegrationFlowContext.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/dsl/context/IntegrationFlowContext.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2017 the original author or authors. + * Copyright 2016-2018 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. @@ -36,7 +36,7 @@ import org.springframework.messaging.MessageChannel; import org.springframework.util.Assert; /** - * A public API for dynamic (manual) registration of {@link IntegrationFlow}, + * A public API for dynamic (manual) registration of {@link IntegrationFlow}s, * not via standard bean registration phase. *

* The bean of this component is provided via framework automatically. @@ -45,7 +45,7 @@ import org.springframework.util.Assert; *

* The typical use-case, and, therefore algorithm, is: *