diff --git a/spring-integration-core/src/main/java/org/springframework/integration/config/xml/IntegrationNamespaceUtils.java b/spring-integration-core/src/main/java/org/springframework/integration/config/xml/IntegrationNamespaceUtils.java
index 55db4371f9..8d572aab83 100644
--- a/spring-integration-core/src/main/java/org/springframework/integration/config/xml/IntegrationNamespaceUtils.java
+++ b/spring-integration-core/src/main/java/org/springframework/integration/config/xml/IntegrationNamespaceUtils.java
@@ -36,6 +36,7 @@ import org.w3c.dom.Element;
* @author Marius Bogoevici
* @author Alex Peters
* @author Oleg Zhurakousky
+ * @author Gary Russell
*/
public abstract class IntegrationNamespaceUtils {
@@ -148,9 +149,18 @@ public abstract class IntegrationNamespaceUtils {
public static void configurePollerMetadata(Element pollerElement, BeanDefinitionBuilder targetBuilder,
ParserContext parserContext) {
if (pollerElement.hasAttribute("ref")) {
- if (pollerElement.getAttributes().getLength() != 1) {
- parserContext.getReaderContext().error(
- "A 'poller' element that provides a 'ref' must have no other attributes.", pollerElement);
+ int numberOfAttributes = pollerElement.getAttributes().getLength();
+ if (numberOfAttributes != 1) {
+ /*
+ * When importing the core namespace, e.g. into jdbc, we get a 'default="false"' attribute,
+ * even if not explicitly declared.
+ */
+ if (!(numberOfAttributes == 2 &&
+ pollerElement.hasAttribute("default") &&
+ pollerElement.getAttribute("default").equals("false"))) {
+ parserContext.getReaderContext().error(
+ "A 'poller' element that provides a 'ref' must have no other attributes.", pollerElement);
+ }
}
if (pollerElement.getChildNodes().getLength() != 0) {
parserContext.getReaderContext().error(
diff --git a/spring-integration-jdbc/src/test/java/org/springframework/integration/jdbc/config/InnerPollerParserTests-context.xml b/spring-integration-jdbc/src/test/java/org/springframework/integration/jdbc/config/InnerPollerParserTests-context.xml
new file mode 100644
index 0000000000..aaa25ba9c1
--- /dev/null
+++ b/spring-integration-jdbc/src/test/java/org/springframework/integration/jdbc/config/InnerPollerParserTests-context.xml
@@ -0,0 +1,22 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/spring-integration-jdbc/src/test/java/org/springframework/integration/jdbc/config/InnerPollerParserTests.java b/spring-integration-jdbc/src/test/java/org/springframework/integration/jdbc/config/InnerPollerParserTests.java
new file mode 100644
index 0000000000..42639caaea
--- /dev/null
+++ b/spring-integration-jdbc/src/test/java/org/springframework/integration/jdbc/config/InnerPollerParserTests.java
@@ -0,0 +1,147 @@
+/*
+ * Copyright 2002-2011 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.jdbc.config;
+
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
+import org.junit.Test;
+import org.springframework.beans.factory.parsing.BeanDefinitionParsingException;
+import org.springframework.context.support.ClassPathXmlApplicationContext;
+import org.springframework.context.support.GenericXmlApplicationContext;
+import org.springframework.core.io.ByteArrayResource;
+import org.springframework.core.io.Resource;
+
+/**
+ * @author Gary Russell
+ * @since 2.0.5
+ *
+ */
+public class InnerPollerParserTests {
+
+ @Test
+ public void testRefGood() {
+ new ClassPathXmlApplicationContext("InnerPollerParserTests-context.xml", InnerPollerParserTests.class);
+ }
+
+ @Test
+ public void testRefExtraAttribute() {
+ try {
+ // Load context from a String to avoid IDEs reporting the invalid configuration
+ String badContext =
+ "" +
+ "" +
+ "" +
+ " " +
+ "" +
+ " " +
+ "" +
+ " " +
+ " " + // <<<<< fixed-rate not allowed here
+ " " +
+ "" +
+ " " +
+ " " +
+ " " +
+ "";
+
+ Resource resource = new ByteArrayResource(badContext.getBytes());
+ new GenericXmlApplicationContext(resource);
+ fail("Expected Failure to load ApplicationContext");
+ } catch (BeanDefinitionParsingException bdpe) {
+ assertTrue(bdpe.getMessage().startsWith("Configuration problem: A 'poller' element that provides a 'ref' must have no other attributes."));
+ }
+ }
+
+ @Test
+ public void testRefDefaultTrue() {
+ try {
+ // Load context from a String to avoid IDEs reporting the invalid configuration
+ String badContext =
+ "" +
+ "" +
+ "" +
+ " " +
+ "" +
+ " " +
+ "" +
+ " " +
+ " " + // <<<<< default true not allowed here
+ " " +
+ "" +
+ " " +
+ " " +
+ " " +
+ "";
+
+ Resource resource = new ByteArrayResource(badContext.getBytes());
+ new GenericXmlApplicationContext(resource);
+ fail("Expected Failure to load ApplicationContext");
+ } catch (BeanDefinitionParsingException bdpe) {
+ assertTrue(bdpe.getMessage().startsWith("Configuration problem: A 'poller' element that provides a 'ref' must have no other attributes."));
+ }
+ }
+
+ @Test
+ public void testRefExtraAttributeAndDefaultFalse() {
+ try {
+ // Load context from a String to avoid IDEs reporting the invalid configuration
+ String badContext =
+ "" +
+ "" +
+ "" +
+ " " +
+ "" +
+ " " +
+ "" +
+ " " +
+ " " + // <<<<< fixed-rate not allowed here
+ " " +
+ "" +
+ " " +
+ " " +
+ " " +
+ "";
+
+ Resource resource = new ByteArrayResource(badContext.getBytes());
+ new GenericXmlApplicationContext(resource);
+ fail("Expected Failure to load ApplicationContext");
+ } catch (BeanDefinitionParsingException bdpe) {
+ assertTrue(bdpe.getMessage().startsWith("Configuration problem: A 'poller' element that provides a 'ref' must have no other attributes."));
+ }
+ }
+}