diff --git a/spring-integration-core/src/main/java/org/springframework/integration/config/xml/AbstractPollingInboundChannelAdapterParser.java b/spring-integration-core/src/main/java/org/springframework/integration/config/xml/AbstractPollingInboundChannelAdapterParser.java
index fd1771761b..a1f4308413 100644
--- a/spring-integration-core/src/main/java/org/springframework/integration/config/xml/AbstractPollingInboundChannelAdapterParser.java
+++ b/spring-integration-core/src/main/java/org/springframework/integration/config/xml/AbstractPollingInboundChannelAdapterParser.java
@@ -20,6 +20,7 @@ import org.w3c.dom.Element;
import org.springframework.beans.BeanMetadataElement;
import org.springframework.beans.factory.config.BeanDefinition;
+import org.springframework.beans.factory.config.RuntimeBeanReference;
import org.springframework.beans.factory.support.AbstractBeanDefinition;
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
import org.springframework.beans.factory.xml.ParserContext;
@@ -45,9 +46,19 @@ public abstract class AbstractPollingInboundChannelAdapterParser extends Abstrac
BeanDefinitionBuilder adapterBuilder = BeanDefinitionBuilder
.genericBeanDefinition(SourcePollingChannelAdapterFactoryBean.class);
- String channelAdapterId = this.resolveId(element, adapterBuilder.getRawBeanDefinition(), parserContext);
- String sourceBeanName = channelAdapterId + ".source";
- parserContext.getRegistry().registerBeanDefinition(sourceBeanName, (BeanDefinition) source);
+ String sourceBeanName = null;
+
+ if (source instanceof BeanDefinition) {
+ String channelAdapterId = this.resolveId(element, adapterBuilder.getRawBeanDefinition(), parserContext);
+ sourceBeanName = channelAdapterId + ".source";
+ parserContext.getRegistry().registerBeanDefinition(sourceBeanName, (BeanDefinition) source);
+ }
+ else if (source instanceof RuntimeBeanReference) {
+ sourceBeanName = ((RuntimeBeanReference) source).getBeanName();
+ }
+ else {
+ parserContext.getReaderContext().error("Wrong 'source' type: must be 'BeanDefinition' or 'RuntimeBeanReference'", source);
+ }
adapterBuilder.addPropertyReference("source", sourceBeanName);
adapterBuilder.addPropertyReference("outputChannel", channelName);
diff --git a/spring-integration-core/src/test/java/org/springframework/integration/config/ChannelAdapterParserTests-context.xml b/spring-integration-core/src/test/java/org/springframework/integration/config/ChannelAdapterParserTests-context.xml
index 933963f608..7a275d23a7 100644
--- a/spring-integration-core/src/test/java/org/springframework/integration/config/ChannelAdapterParserTests-context.xml
+++ b/spring-integration-core/src/test/java/org/springframework/integration/config/ChannelAdapterParserTests-context.xml
@@ -65,4 +65,12 @@
+
+
+
+
+
+
+
+
diff --git a/spring-integration-core/src/test/java/org/springframework/integration/config/ChannelAdapterParserTests.java b/spring-integration-core/src/test/java/org/springframework/integration/config/ChannelAdapterParserTests.java
index 0d96ea5e01..9411fa95f0 100644
--- a/spring-integration-core/src/test/java/org/springframework/integration/config/ChannelAdapterParserTests.java
+++ b/spring-integration-core/src/test/java/org/springframework/integration/config/ChannelAdapterParserTests.java
@@ -20,6 +20,7 @@ import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
@@ -37,6 +38,7 @@ import org.springframework.integration.MessageChannel;
import org.springframework.integration.MessageDeliveryException;
import org.springframework.integration.MessageDispatchingException;
import org.springframework.integration.channel.DirectChannel;
+import org.springframework.integration.core.MessageSource;
import org.springframework.integration.core.PollableChannel;
import org.springframework.integration.endpoint.EventDrivenConsumer;
import org.springframework.integration.endpoint.SourcePollingChannelAdapter;
@@ -294,8 +296,22 @@ public class ChannelAdapterParserTests {
}
}
+ @Test
+ public void testMessageSourceRef() {
+ PollableChannel channel = this.applicationContext.getBean("messageSourceRefChannel", PollableChannel.class);
+
+ Message> message = channel.receive(5000);
+ assertNotNull(message);
+ assertEquals("test", message.getPayload());
+
+ MessageSource> testMessageSource = this.applicationContext.getBean("testMessageSource", MessageSource.class);
+ SourcePollingChannelAdapter adapterWithMessageSourceRef = this.applicationContext.getBean("adapterWithMessageSourceRef", SourcePollingChannelAdapter.class);
+ MessageSource> source = TestUtils.getPropertyValue(adapterWithMessageSourceRef, "source", MessageSource.class);
+ assertSame(testMessageSource, source);
+ }
+
public static class SampleBean {
- private String message = "hello";
+ private final String message = "hello";
String getMessage() {
return message;