BATCH-63:added id and class attributes to <listener> element
This commit is contained in:
@@ -271,14 +271,30 @@ public class StepParser {
|
||||
DomUtils.getChildElementsByTagName(listenersElement, "listener");
|
||||
if (listenerElements != null) {
|
||||
for (Element listenerElement : listenerElements) {
|
||||
String id = listenerElement.getAttribute("id");
|
||||
String listenerRef = listenerElement.getAttribute("ref");
|
||||
if (StringUtils.hasText(listenerRef)) {
|
||||
listenerRefs.add(listenerRef);
|
||||
RuntimeBeanReference bean = new RuntimeBeanReference(listenerRef);
|
||||
if (bean != null) {
|
||||
listenerBeans.add(bean);
|
||||
}
|
||||
String className = listenerElement.getAttribute("class");
|
||||
if ((StringUtils.hasText(id) || StringUtils.hasText(className))
|
||||
&& StringUtils.hasText(listenerRef)) {
|
||||
throw new BeanCreationException("Both 'id' or 'ref' plus 'class' specified; use 'class' with an optional 'id' or just 'ref' for <" + listenerElement.getTagName() + "> element with" + (StringUtils.hasText(id) ? " id=\"" + id + "\"" : "" ) + (StringUtils.hasText(className) ? " class=\"" + className + "\"" : "") + (StringUtils.hasText(listenerRef) ? " ref=\"" + listenerRef + "\"" : ""));
|
||||
}
|
||||
if (StringUtils.hasText(listenerRef)) {
|
||||
listenerRefs.add(listenerRef);
|
||||
BeanReference bean = new RuntimeBeanReference(listenerRef);
|
||||
listenerBeans.add(bean);
|
||||
}
|
||||
else if (StringUtils.hasText(className)) {
|
||||
RootBeanDefinition beanDef = new RootBeanDefinition(className, null, null);
|
||||
if (!StringUtils.hasText(id)) {
|
||||
id = parserContext.getReaderContext().generateBeanName(beanDef);
|
||||
}
|
||||
parserContext.getRegistry().registerBeanDefinition(id, beanDef);
|
||||
BeanReference bean = new RuntimeBeanReference(id);
|
||||
listenerBeans.add(bean);
|
||||
}
|
||||
else {
|
||||
throw new BeanCreationException("Neither 'ref' or 'class' specified for <" + listenerElement.getTagName() + "> element");
|
||||
}
|
||||
}
|
||||
}
|
||||
ManagedList arguments = new ManagedList();
|
||||
|
||||
@@ -225,8 +225,9 @@
|
||||
</xsd:annotation>
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="listener">
|
||||
<xsd:element name="listener" minOccurs="1" maxOccurs="unbounded">
|
||||
<xsd:complexType>
|
||||
<xsd:attribute name="id" type="xsd:ID"/>
|
||||
<xsd:attribute name="ref" type="xsd:string"/>
|
||||
<xsd:attribute name="class" type="xsd:string"/>
|
||||
</xsd:complexType>
|
||||
|
||||
@@ -29,6 +29,7 @@ import org.springframework.batch.core.JobParameters;
|
||||
import org.springframework.batch.core.repository.JobRepository;
|
||||
import org.springframework.batch.core.repository.support.MapJobRepositoryFactoryBean;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Qualifier;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
@@ -51,6 +52,7 @@ public class StepWithChunkOrientedJobParserTests {
|
||||
private TestReader reader;
|
||||
|
||||
@Autowired
|
||||
@Qualifier("listener")
|
||||
private TestListener listener;
|
||||
|
||||
@Autowired
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
<step name="step1">
|
||||
<chunk-oriented reader="reader" processor="processor" writer="writer">
|
||||
<listeners>
|
||||
<listener class="org.springframework.batch.core.configuration.xml.TestListener"/>
|
||||
<listener ref="listener"/>
|
||||
</listeners>
|
||||
</chunk-oriented>
|
||||
|
||||
Reference in New Issue
Block a user