From d90d4e4d8fdd3f75e49ed9f154fdcbe557b8079c Mon Sep 17 00:00:00 2001 From: Gary Russell Date: Mon, 29 May 2017 17:01:51 -0400 Subject: [PATCH] INT-4283: Restore Registration of Missing Comps JIRA: https://jira.spring.io/browse/INT-4282 Unrecognized components were not added to `targetIntegrationComponents` causing problems such as messge-driven components not starting. --- .../dsl/IntegrationFlowBeanPostProcessor.java | 6 ++- .../dsl/manualflow/ManualFlowTests.java | 53 +++++++++++++++++++ 2 files changed, 57 insertions(+), 2 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 76497a98b6..f9566bb035 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 @@ -66,6 +66,7 @@ import org.springframework.util.StringUtils; * if necessary. * * @author Artem Bilan + * @author Gary Russell * @since 5.0 */ public class IntegrationFlowBeanPostProcessor implements BeanPostProcessor, BeanFactoryAware, @@ -252,8 +253,9 @@ public class IntegrationFlowBeanPostProcessor implements BeanPostProcessor, Bean targetIntegrationComponents.put(component, gatewayId); } else { - String generateBeanName = generateBeanName(component, entry.getValue()); - registerComponent(component, generateBeanName, flowBeanName, registerSingleton); + String generatedBeanName = generateBeanName(component, entry.getValue()); + registerComponent(component, generatedBeanName, flowBeanName, registerSingleton); + targetIntegrationComponents.put(component, generatedBeanName); } } else { diff --git a/spring-integration-core/src/test/java/org/springframework/integration/dsl/manualflow/ManualFlowTests.java b/spring-integration-core/src/test/java/org/springframework/integration/dsl/manualflow/ManualFlowTests.java index e1edfd857c..5f474560e3 100644 --- a/spring-integration-core/src/test/java/org/springframework/integration/dsl/manualflow/ManualFlowTests.java +++ b/spring-integration-core/src/test/java/org/springframework/integration/dsl/manualflow/ManualFlowTests.java @@ -28,6 +28,7 @@ import static org.junit.Assert.fail; import java.util.Date; import java.util.Objects; +import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicReference; import org.junit.Test; @@ -49,9 +50,12 @@ import org.springframework.integration.core.MessagingTemplate; import org.springframework.integration.dsl.IntegrationFlow; import org.springframework.integration.dsl.IntegrationFlowAdapter; import org.springframework.integration.dsl.IntegrationFlowDefinition; +import org.springframework.integration.dsl.IntegrationFlows; +import org.springframework.integration.dsl.MessageProducerSpec; import org.springframework.integration.dsl.channel.MessageChannels; import org.springframework.integration.dsl.context.IntegrationFlowContext; import org.springframework.integration.dsl.context.IntegrationFlowRegistration; +import org.springframework.integration.endpoint.MessageProducerSupport; import org.springframework.integration.handler.AbstractReplyProducingMessageHandler; import org.springframework.messaging.Message; import org.springframework.messaging.MessageChannel; @@ -66,6 +70,7 @@ import org.springframework.test.context.junit4.SpringRunner; /** * @author Artem Bilan + * @author Gary Russell * * @since 5.0 */ @@ -80,6 +85,54 @@ public class ManualFlowTests { @Autowired private BeanFactory beanFactory; + @Test + public void testWithAnonymousMessageProducerStart() { + final AtomicBoolean started = new AtomicBoolean(); + MessageProducerSupport producer = new MessageProducerSupport() { + + @Override + protected void doStart() { + started.set(true); + super.doStart(); + } + + }; + QueueChannel channel = new QueueChannel(); + IntegrationFlow flow = IntegrationFlows.from(producer) + .channel(channel) + .get(); + this.integrationFlowContext.registration(flow).register(); + assertTrue(started.get()); + } + + @Test + public void testWithAnonymousMessageProducerSpecStart() { + final AtomicBoolean started = new AtomicBoolean(); + class MyProducer extends MessageProducerSupport { + + @Override + protected void doStart() { + started.set(true); + super.doStart(); + } + + } + class MyProducerSpec extends MessageProducerSpec { + + MyProducerSpec(MyProducer producer) { + super(producer); + } + + } + MyProducerSpec spec = new MyProducerSpec(new MyProducer()); + QueueChannel channel = new QueueChannel(); + IntegrationFlow flow = IntegrationFlows.from(spec.id("foo")) + .channel(channel) + .get(); + this.integrationFlowContext.registration(flow).register(); + assertTrue(started.get()); + } + @Test public void testManualFlowRegistration() throws InterruptedException { IntegrationFlow myFlow = f -> f