From 08ebc6684ffbf7fffdc0de58ca6ed77c1a3b9042 Mon Sep 17 00:00:00 2001 From: Artem Bilan Date: Mon, 11 Jun 2018 17:02:51 -0400 Subject: [PATCH] INT-4485: Don't register bean twice for DSL Specs JIRA: https://jira.spring.io/browse/INT-4485 The `IntegrationFlowBeanPostProcessor` performs extra bean registration for the `IntegrationComponentSpec.get()` result. Essentially it is going to be the same object in the end, but during bean registration phase we end up with names conflict. * Remove an explicit `registerComponent()` for the `IntegrationComponentSpec.get()` * Modify `CorrelationHandlerTests` for all possible usage for the `MessageChannelSpec`, which is essentially a `FactoryBean` **Cherry-pick to 5.0.x** --- .../dsl/IntegrationFlowBeanPostProcessor.java | 1 - .../correlation/CorrelationHandlerTests.java | 24 +++++++++++++++---- 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/spring-integration-core/src/main/java/org/springframework/integration/config/dsl/IntegrationFlowBeanPostProcessor.java b/spring-integration-core/src/main/java/org/springframework/integration/config/dsl/IntegrationFlowBeanPostProcessor.java index c3f792ef64..44b3d8d205 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/config/dsl/IntegrationFlowBeanPostProcessor.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/config/dsl/IntegrationFlowBeanPostProcessor.java @@ -281,7 +281,6 @@ public class IntegrationFlowBeanPostProcessor } private void processIntegrationComponentSpec(IntegrationComponentSpec bean) { - registerComponent(bean.get(), generateBeanName(bean.get(), bean.getId())); if (bean instanceof ComponentsRegistration) { Map componentsToRegister = ((ComponentsRegistration) bean).getComponentsToRegister(); if (!CollectionUtils.isEmpty(componentsToRegister)) { diff --git a/spring-integration-core/src/test/java/org/springframework/integration/dsl/correlation/CorrelationHandlerTests.java b/spring-integration-core/src/test/java/org/springframework/integration/dsl/correlation/CorrelationHandlerTests.java index d54f376eb6..596b2e90a2 100644 --- a/spring-integration-core/src/test/java/org/springframework/integration/dsl/correlation/CorrelationHandlerTests.java +++ b/spring-integration-core/src/test/java/org/springframework/integration/dsl/correlation/CorrelationHandlerTests.java @@ -43,6 +43,7 @@ import org.springframework.integration.channel.QueueChannel; import org.springframework.integration.config.EnableIntegration; import org.springframework.integration.dsl.IntegrationFlow; import org.springframework.integration.dsl.IntegrationFlows; +import org.springframework.integration.dsl.channel.MessageChannelSpec; import org.springframework.integration.dsl.channel.MessageChannels; import org.springframework.integration.handler.MessageTriggerAction; import org.springframework.integration.support.MessageBuilder; @@ -176,10 +177,15 @@ public class CorrelationHandlerTests { } @Bean - public IntegrationFlow splitResequenceFlow() { + public MessageChannelSpec executorChannel() { + return MessageChannels.executor(taskExecutor()); + } + + @Bean + public IntegrationFlow splitResequenceFlow(MessageChannel executorChannel) { return f -> f.enrichHeaders(s -> s.header("FOO", "BAR")) .split("testSplitterData", "buildList", c -> c.applySequence(false)) - .channel(MessageChannels.executor(taskExecutor())) + .channel(executorChannel) .split(Message.class, Message::getPayload, c -> c.applySequence(false)) .channel(MessageChannels.executor(taskExecutor())) .split(s -> s @@ -228,6 +234,11 @@ public class CorrelationHandlerTests { .channel(MessageChannels.queue("subscriberAggregateResult")); } + @Bean + public MessageChannelSpec barrierResults() { + return MessageChannels.queue("barrierResults"); + } + @Bean public IntegrationFlow barrierFlow() { return f -> f @@ -239,13 +250,18 @@ public class CorrelationHandlerTests { .skip(1) .findFirst() .get())) - .channel(MessageChannels.queue("barrierResults")); + .channel("barrierResults"); + } + + @Bean + public MessageChannelSpec releaseChannel() { + return MessageChannels.queue("releaseChannel"); } @Bean @DependsOn("barrierFlow") public IntegrationFlow releaseBarrierFlow(MessageTriggerAction barrierTriggerAction) { - return IntegrationFlows.from(MessageChannels.queue("releaseChannel")) + return IntegrationFlows.from(releaseChannel()) .trigger(barrierTriggerAction, e -> e.poller(p -> p.fixedDelay(100))) .get();