diff --git a/org.springframework.integration/src/main/java/org/springframework/integration/config/xml/PollerParser.java b/org.springframework.integration/src/main/java/org/springframework/integration/config/xml/PollerParser.java
index ac18c44252..a4054a4e44 100644
--- a/org.springframework.integration/src/main/java/org/springframework/integration/config/xml/PollerParser.java
+++ b/org.springframework.integration/src/main/java/org/springframework/integration/config/xml/PollerParser.java
@@ -43,9 +43,18 @@ public class PollerParser extends AbstractBeanDefinitionParser {
String id = super.resolveId(element, definition, parserContext);
if (element.getAttribute("default").equals("true")) {
if (parserContext.getRegistry().isBeanNameInUse(IntegrationContextUtils.DEFAULT_POLLER_METADATA_BEAN_NAME)) {
- parserContext.getReaderContext().error("only one default element is allowed per context", element);
+ parserContext.getReaderContext().error("Only one default element is allowed per context.", element);
}
- parserContext.getRegistry().registerAlias(id, IntegrationContextUtils.DEFAULT_POLLER_METADATA_BEAN_NAME);
+ if (StringUtils.hasText(id)) {
+ parserContext.getRegistry().registerAlias(id, IntegrationContextUtils.DEFAULT_POLLER_METADATA_BEAN_NAME);
+ }
+ else {
+ id = IntegrationContextUtils.DEFAULT_POLLER_METADATA_BEAN_NAME;
+ }
+ }
+ else if (!StringUtils.hasText(id)) {
+ parserContext.getReaderContext().error(
+ "The 'id' attribute is required for a top-level poller element unless it is the default poller.", element);
}
return id;
}
diff --git a/org.springframework.integration/src/test/java/org/springframework/integration/config/xml/PollerParserTests.java b/org.springframework.integration/src/test/java/org/springframework/integration/config/xml/PollerParserTests.java
new file mode 100644
index 0000000000..23c7fb96aa
--- /dev/null
+++ b/org.springframework.integration/src/test/java/org/springframework/integration/config/xml/PollerParserTests.java
@@ -0,0 +1,65 @@
+/*
+ * Copyright 2002-2008 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.assertEquals;
+import static org.junit.Assert.assertNotNull;
+
+import org.junit.Test;
+
+import org.springframework.beans.factory.parsing.BeanDefinitionParsingException;
+import org.springframework.context.ApplicationContext;
+import org.springframework.context.support.ClassPathXmlApplicationContext;
+import org.springframework.integration.context.IntegrationContextUtils;
+
+/**
+ * @author Mark Fisher
+ */
+public class PollerParserTests {
+
+ @Test
+ public void defaultPollerWithId() {
+ ApplicationContext context = new ClassPathXmlApplicationContext(
+ "defaultPollerWithId.xml", PollerParserTests.class);
+ Object poller = context.getBean("defaultPollerWithId");
+ assertNotNull(poller);
+ Object defaultPoller = context.getBean(IntegrationContextUtils.DEFAULT_POLLER_METADATA_BEAN_NAME);
+ assertNotNull(defaultPoller);
+ assertEquals(defaultPoller, context.getBean("defaultPollerWithId"));
+ }
+
+ @Test
+ public void defaultPollerWithoutId() {
+ ApplicationContext context = new ClassPathXmlApplicationContext(
+ "defaultPollerWithoutId.xml", PollerParserTests.class);
+ Object defaultPoller = context.getBean(IntegrationContextUtils.DEFAULT_POLLER_METADATA_BEAN_NAME);
+ assertNotNull(defaultPoller);
+ }
+
+ @Test(expected = BeanDefinitionParsingException.class)
+ public void multipleDefaultPollers() {
+ new ClassPathXmlApplicationContext(
+ "multipleDefaultPollers.xml", PollerParserTests.class);
+ }
+
+ @Test(expected = BeanDefinitionParsingException.class)
+ public void topLevelPollerWithoutId() {
+ new ClassPathXmlApplicationContext(
+ "topLevelPollerWithoutId.xml", PollerParserTests.class);
+ }
+
+}
diff --git a/org.springframework.integration/src/test/java/org/springframework/integration/config/xml/defaultPollerWithId.xml b/org.springframework.integration/src/test/java/org/springframework/integration/config/xml/defaultPollerWithId.xml
new file mode 100644
index 0000000000..b3eb26ceb6
--- /dev/null
+++ b/org.springframework.integration/src/test/java/org/springframework/integration/config/xml/defaultPollerWithId.xml
@@ -0,0 +1,14 @@
+
+
+
+
+
+
+
+
diff --git a/org.springframework.integration/src/test/java/org/springframework/integration/config/xml/defaultPollerWithoutId.xml b/org.springframework.integration/src/test/java/org/springframework/integration/config/xml/defaultPollerWithoutId.xml
new file mode 100644
index 0000000000..c66114030a
--- /dev/null
+++ b/org.springframework.integration/src/test/java/org/springframework/integration/config/xml/defaultPollerWithoutId.xml
@@ -0,0 +1,14 @@
+
+
+
+
+
+
+
+
diff --git a/org.springframework.integration/src/test/java/org/springframework/integration/config/xml/multipleDefaultPollers.xml b/org.springframework.integration/src/test/java/org/springframework/integration/config/xml/multipleDefaultPollers.xml
new file mode 100644
index 0000000000..bdad6c1f93
--- /dev/null
+++ b/org.springframework.integration/src/test/java/org/springframework/integration/config/xml/multipleDefaultPollers.xml
@@ -0,0 +1,18 @@
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/org.springframework.integration/src/test/java/org/springframework/integration/config/xml/topLevelPollerWithoutId.xml b/org.springframework.integration/src/test/java/org/springframework/integration/config/xml/topLevelPollerWithoutId.xml
new file mode 100644
index 0000000000..62cbc8ddcf
--- /dev/null
+++ b/org.springframework.integration/src/test/java/org/springframework/integration/config/xml/topLevelPollerWithoutId.xml
@@ -0,0 +1,14 @@
+
+
+
+
+
+
+
+