diff --git a/org.springframework.integration/src/main/java/org/springframework/integration/config/ConsumerEndpointFactoryBean.java b/org.springframework.integration/src/main/java/org/springframework/integration/config/ConsumerEndpointFactoryBean.java
index 8a3ddafb71..06c9bb4335 100644
--- a/org.springframework.integration/src/main/java/org/springframework/integration/config/ConsumerEndpointFactoryBean.java
+++ b/org.springframework.integration/src/main/java/org/springframework/integration/config/ConsumerEndpointFactoryBean.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2008 the original author or authors.
+ * 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.
@@ -40,7 +40,7 @@ import org.springframework.util.Assert;
*/
public class ConsumerEndpointFactoryBean implements FactoryBean, BeanFactoryAware, BeanNameAware, InitializingBean, ApplicationListener {
- private final MessageHandler handler;
+ private volatile MessageHandler handler;
private volatile String beanName;
@@ -58,10 +58,15 @@ public class ConsumerEndpointFactoryBean implements FactoryBean, BeanFactoryAwar
private final Object initializationMonitor = new Object();
+ private final Object handlerMonitor = new Object();
- public ConsumerEndpointFactoryBean(MessageHandler handler) {
+
+ public void setHandler(MessageHandler handler) {
Assert.notNull(handler, "handler must not be null");
- this.handler = handler;
+ synchronized (this.handlerMonitor) {
+ Assert.isNull(this.handler, "handler cannot be overridden");
+ this.handler = handler;
+ }
}
diff --git a/org.springframework.integration/src/main/java/org/springframework/integration/config/xml/AbstractConsumerEndpointParser.java b/org.springframework.integration/src/main/java/org/springframework/integration/config/xml/AbstractConsumerEndpointParser.java
index 38de3d2b06..853e7e05d8 100644
--- a/org.springframework.integration/src/main/java/org/springframework/integration/config/xml/AbstractConsumerEndpointParser.java
+++ b/org.springframework.integration/src/main/java/org/springframework/integration/config/xml/AbstractConsumerEndpointParser.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2008 the original author or authors.
+ * 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.
@@ -73,7 +73,7 @@ public abstract class AbstractConsumerEndpointParser extends AbstractBeanDefinit
BeanDefinitionBuilder builder = BeanDefinitionBuilder.genericBeanDefinition(
IntegrationNamespaceUtils.BASE_PACKAGE + ".config.ConsumerEndpointFactoryBean");
String handlerBeanName = BeanDefinitionReaderUtils.registerWithGeneratedName(handlerBeanDefinition, parserContext.getRegistry());
- builder.addConstructorArgReference(handlerBeanName);
+ builder.addPropertyReference("handler", handlerBeanName);
String inputChannelName = element.getAttribute(inputChannelAttributeName);
if (!parserContext.getRegistry().containsBeanDefinition(inputChannelName)) {
BeanDefinitionBuilder channelDef = BeanDefinitionBuilder.genericBeanDefinition(
diff --git a/org.springframework.integration/src/main/java/org/springframework/integration/config/xml/AbstractOutboundChannelAdapterParser.java b/org.springframework.integration/src/main/java/org/springframework/integration/config/xml/AbstractOutboundChannelAdapterParser.java
index 064751dc61..e866a634f1 100644
--- a/org.springframework.integration/src/main/java/org/springframework/integration/config/xml/AbstractOutboundChannelAdapterParser.java
+++ b/org.springframework.integration/src/main/java/org/springframework/integration/config/xml/AbstractOutboundChannelAdapterParser.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2008 the original author or authors.
+ * 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.
@@ -37,7 +37,7 @@ public abstract class AbstractOutboundChannelAdapterParser extends AbstractChann
Element pollerElement = DomUtils.getChildElementByTagName(element, "poller");
BeanDefinitionBuilder builder = BeanDefinitionBuilder.genericBeanDefinition(
IntegrationNamespaceUtils.BASE_PACKAGE + ".config.ConsumerEndpointFactoryBean");
- builder.addConstructorArgReference(this.parseAndRegisterConsumer(element, parserContext));
+ builder.addPropertyReference("handler", this.parseAndRegisterConsumer(element, parserContext));
if (pollerElement != null) {
if (!StringUtils.hasText(channelName)) {
parserContext.getReaderContext().error(
diff --git a/org.springframework.integration/src/test/java/org/springframework/integration/config/xml/ConstructorAutowireTest-context.xml b/org.springframework.integration/src/test/java/org/springframework/integration/config/xml/ConstructorAutowireTest-context.xml
new file mode 100644
index 0000000000..77d49ea5bd
--- /dev/null
+++ b/org.springframework.integration/src/test/java/org/springframework/integration/config/xml/ConstructorAutowireTest-context.xml
@@ -0,0 +1,28 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/org.springframework.integration/src/test/java/org/springframework/integration/config/xml/ConstructorAutowireTest.java b/org.springframework.integration/src/test/java/org/springframework/integration/config/xml/ConstructorAutowireTest.java
new file mode 100644
index 0000000000..2efa74f585
--- /dev/null
+++ b/org.springframework.integration/src/test/java/org/springframework/integration/config/xml/ConstructorAutowireTest.java
@@ -0,0 +1,67 @@
+/*
+ * 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 java.util.List;
+
+import org.junit.Test;
+
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.context.support.ClassPathXmlApplicationContext;
+
+/**
+ * @author Jim Moore
+ * @author Mark Fisher
+ */
+public class ConstructorAutowireTest {
+
+ @Test // INT-568
+ public void testApplicationContextCreation() {
+ new ClassPathXmlApplicationContext("ConstructorAutowireTest-context.xml", ConstructorAutowireTest.class);
+ }
+
+
+ public static class TestService {
+ public String getVal() {
+ return "fooble";
+ }
+ }
+
+
+ public static class TestEndpoint {
+
+ private TestService service;
+
+ @Autowired
+ public TestEndpoint(TestService service) {
+ this.service = service;
+ }
+
+ public String aProducer() {
+ return this.service.getVal();
+ }
+
+ public void aConsumer(String str) {
+ // ignore
+ }
+
+ public List aSplitter(List strs) {
+ return strs;
+ }
+ }
+
+}