From de9f8d7ccd2adbb3e3b5b44d32e7eccfaa8ea72e Mon Sep 17 00:00:00 2001 From: Artem Bilan Date: Mon, 16 Jul 2018 19:40:06 -0400 Subject: [PATCH] INT-4501: Don't call getBean from BPP.setBFactory JIRA: https://jira.spring.io/browse/INT-4501 The call to the `IntegrationFlowBeanPostProcessor#setBeanFactory` happens during BPP creation. The introduced call to `beanFactory#getBean` triggers a lot of bean creations. For those beans not all `BPP`s are applied. * Obtain a `flowContext` bean in lazy-load manner **Cherry-pick to 5.0.x** --- .../dsl/context/IntegrationFlowBeanPostProcessor.java | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/spring-integration-core/src/main/java/org/springframework/integration/dsl/context/IntegrationFlowBeanPostProcessor.java b/spring-integration-core/src/main/java/org/springframework/integration/dsl/context/IntegrationFlowBeanPostProcessor.java index ce56e212ba..311b00196d 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/dsl/context/IntegrationFlowBeanPostProcessor.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/dsl/context/IntegrationFlowBeanPostProcessor.java @@ -93,7 +93,7 @@ public class IntegrationFlowBeanPostProcessor private ConfigurableListableBeanFactory beanFactory; - private IntegrationFlowContext flowContext; + private volatile IntegrationFlowContext flowContext; @Override public void setApplicationContext(ApplicationContext applicationContext) throws BeansException { @@ -105,8 +105,6 @@ public class IntegrationFlowBeanPostProcessor this.applicationContext = (ConfigurableApplicationContext) applicationContext; this.beanFactory = this.applicationContext.getBeanFactory(); this.embeddedValueResolver = new EmbeddedValueResolver(this.beanFactory); - this.flowContext = this.beanFactory.getBean(IntegrationFlowContext.class); - Assert.notNull(this.flowContext, "There must be an IntegrationFlowContext in the application context"); } @Override @@ -140,6 +138,9 @@ public class IntegrationFlowBeanPostProcessor private Object processStandardIntegrationFlow(StandardIntegrationFlow flow, String flowBeanName) { String flowNamePrefix = flowBeanName + "."; + if (this.flowContext == null) { + this.flowContext = this.beanFactory.getBean(IntegrationFlowContext.class); + } boolean useFlowIdAsPrefix = this.flowContext.isUseIdAsPrefix(flowBeanName); int subFlowNameIndex = 0; int channelNameIndex = 0;