diff --git a/org.springframework.integration/src/main/java/org/springframework/integration/config/xml/AbstractIntegrationNamespaceHandler.java b/org.springframework.integration/src/main/java/org/springframework/integration/config/xml/AbstractIntegrationNamespaceHandler.java
index c40d90d881..523b6eedc5 100644
--- a/org.springframework.integration/src/main/java/org/springframework/integration/config/xml/AbstractIntegrationNamespaceHandler.java
+++ b/org.springframework.integration/src/main/java/org/springframework/integration/config/xml/AbstractIntegrationNamespaceHandler.java
@@ -19,6 +19,8 @@ package org.springframework.integration.config.xml;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
+import org.springframework.beans.factory.BeanFactoryUtils;
+import org.springframework.beans.factory.ListableBeanFactory;
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.beans.factory.config.BeanDefinitionHolder;
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
@@ -28,6 +30,7 @@ import org.springframework.beans.factory.xml.BeanDefinitionParser;
import org.springframework.beans.factory.xml.NamespaceHandler;
import org.springframework.beans.factory.xml.NamespaceHandlerSupport;
import org.springframework.beans.factory.xml.ParserContext;
+import org.springframework.util.ObjectUtils;
/**
* Base class for NamespaceHandlers that registers a BeanFactoryPostProcessor
@@ -57,7 +60,16 @@ public abstract class AbstractIntegrationNamespaceHandler implements NamespaceHa
}
private void registerDefaultConfiguringBeanFactoryPostProcessorIfNecessary(ParserContext parserContext) {
- if (!parserContext.getRegistry().isBeanNameInUse(DEFAULT_CONFIGURING_POSTPROCESSOR_BEAN_NAME)) {
+ boolean alreadyRegistered = false;
+ if (parserContext.getRegistry() instanceof ListableBeanFactory) {
+ alreadyRegistered = ObjectUtils.containsElement(
+ BeanFactoryUtils.beanNamesIncludingAncestors((ListableBeanFactory) parserContext.getRegistry()),
+ DEFAULT_CONFIGURING_POSTPROCESSOR_BEAN_NAME);
+ }
+ else {
+ alreadyRegistered = parserContext.getRegistry().isBeanNameInUse(DEFAULT_CONFIGURING_POSTPROCESSOR_BEAN_NAME);
+ }
+ if (!alreadyRegistered) {
BeanDefinitionBuilder postProcessorBuilder = BeanDefinitionBuilder.genericBeanDefinition(
IntegrationNamespaceUtils.BASE_PACKAGE + ".config.xml." + DEFAULT_CONFIGURING_POSTPROCESSOR_SIMPLE_CLASS_NAME);
BeanDefinitionHolder postProcessorHolder = new BeanDefinitionHolder(
diff --git a/org.springframework.integration/src/test/java/org/springframework/integration/config/xml/DefaultConfiguringBeanFactoryPostProcessorHierarchyTests.java b/org.springframework.integration/src/test/java/org/springframework/integration/config/xml/DefaultConfiguringBeanFactoryPostProcessorHierarchyTests.java
new file mode 100644
index 0000000000..05ae2cd074
--- /dev/null
+++ b/org.springframework.integration/src/test/java/org/springframework/integration/config/xml/DefaultConfiguringBeanFactoryPostProcessorHierarchyTests.java
@@ -0,0 +1,52 @@
+/*
+ * Copyright 2002-2009 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.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.springframework.integration.config.xml;
+
+import static org.junit.Assert.assertSame;
+
+import org.junit.Test;
+
+import org.springframework.beans.factory.xml.XmlBeanDefinitionReader;
+import org.springframework.context.support.ClassPathXmlApplicationContext;
+import org.springframework.context.support.GenericApplicationContext;
+import org.springframework.core.io.ClassPathResource;
+import org.springframework.integration.context.IntegrationContextUtils;
+
+/**
+ * @author Mark Fisher
+ */
+public class DefaultConfiguringBeanFactoryPostProcessorHierarchyTests {
+
+ @Test
+ public void verifySinglePostProcessor() {
+ ClassPathXmlApplicationContext parent = new ClassPathXmlApplicationContext(
+ "hierarchyTests-parent.xml", this.getClass());
+ parent.refresh();
+ GenericApplicationContext child = new GenericApplicationContext();
+ child.setParent(parent);
+ XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(child);
+ reader.loadBeanDefinitions(new ClassPathResource("hierarchyTests-child.xml", this.getClass()));
+ child.refresh();
+ assertSame(parent.getBean(IntegrationContextUtils.ERROR_CHANNEL_BEAN_NAME),
+ child.getBean(IntegrationContextUtils.ERROR_CHANNEL_BEAN_NAME));
+ assertSame(parent.getBean(IntegrationContextUtils.NULL_CHANNEL_BEAN_NAME),
+ child.getBean(IntegrationContextUtils.NULL_CHANNEL_BEAN_NAME));
+ assertSame(parent.getBean(IntegrationContextUtils.TASK_SCHEDULER_BEAN_NAME),
+ child.getBean(IntegrationContextUtils.TASK_SCHEDULER_BEAN_NAME));
+ }
+
+}
diff --git a/org.springframework.integration/src/test/java/org/springframework/integration/config/xml/hierarchyTests-child.xml b/org.springframework.integration/src/test/java/org/springframework/integration/config/xml/hierarchyTests-child.xml
new file mode 100644
index 0000000000..5e079e31a7
--- /dev/null
+++ b/org.springframework.integration/src/test/java/org/springframework/integration/config/xml/hierarchyTests-child.xml
@@ -0,0 +1,12 @@
+
+
+
+
+
+
diff --git a/org.springframework.integration/src/test/java/org/springframework/integration/config/xml/hierarchyTests-parent.xml b/org.springframework.integration/src/test/java/org/springframework/integration/config/xml/hierarchyTests-parent.xml
new file mode 100644
index 0000000000..91bfad3f1e
--- /dev/null
+++ b/org.springframework.integration/src/test/java/org/springframework/integration/config/xml/hierarchyTests-parent.xml
@@ -0,0 +1,12 @@
+
+
+
+
+
+