PollerParser correctly prevents multiple triggers

This commit is contained in:
Mark Fisher
2011-09-27 16:52:00 -04:00
parent 6e662f48eb
commit 037e8aabc1
3 changed files with 23 additions and 4 deletions

View File

@@ -120,7 +120,7 @@ public class PollerParser extends AbstractBeanDefinitionParser {
}
triggerBeanNames.add(triggerAttribute);
}
else if (StringUtils.hasText(fixedRateAttribute)) {
if (StringUtils.hasText(fixedRateAttribute)) {
BeanDefinitionBuilder builder = BeanDefinitionBuilder.genericBeanDefinition(PERIODIC_TRIGGER_CLASSNAME);
builder.addConstructorArgValue(fixedRateAttribute);
if (StringUtils.hasText(timeUnit)) {
@@ -131,7 +131,7 @@ public class PollerParser extends AbstractBeanDefinitionParser {
builder.getBeanDefinition(), parserContext.getRegistry());
triggerBeanNames.add(triggerBeanName);
}
else if (StringUtils.hasText(fixedDelayAttribute)) {
if (StringUtils.hasText(fixedDelayAttribute)) {
BeanDefinitionBuilder builder = BeanDefinitionBuilder.genericBeanDefinition(PERIODIC_TRIGGER_CLASSNAME);
builder.addConstructorArgValue(fixedDelayAttribute);
if (StringUtils.hasText(timeUnit)) {
@@ -142,7 +142,7 @@ public class PollerParser extends AbstractBeanDefinitionParser {
builder.getBeanDefinition(), parserContext.getRegistry());
triggerBeanNames.add(triggerBeanName);
}
else if (StringUtils.hasText(cronAttribute)) {
if (StringUtils.hasText(cronAttribute)) {
if (StringUtils.hasText(timeUnit)) {
parserContext.getReaderContext().error("The 'time-unit' attribute cannot be used with a 'cron' trigger.", pollerElement);
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2009 the original author or authors.
* 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.
@@ -118,4 +118,11 @@ public class PollerParserTests {
new ClassPathXmlApplicationContext(
"defaultPollerWithRef.xml", PollerParserTests.class);
}
@Test(expected=BeanDefinitionParsingException.class)
public void pollerWithCronAndFixedDelay() {
new ClassPathXmlApplicationContext(
"pollerWithCronAndFixedDelay.xml", PollerParserTests.class);
}
}

View File

@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<beans:beans xmlns="http://www.springframework.org/schema/integration"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:beans="http://www.springframework.org/schema/beans"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/integration
http://www.springframework.org/schema/integration/spring-integration.xsd">
<poller id="poller" cron="7 * * * * ?" fixed-delay="3000"/>
</beans:beans>