RESOLVED - issue BATCH-1282: JobRegistryBeanProcessor skips jobs that in XML namespace unless they are injected as dependency
Used SmartFactoryBean
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<beansProjectDescription>
|
||||
<version>1</version>
|
||||
<pluginVersion><![CDATA[2.2.2.RELEASE]]></pluginVersion>
|
||||
<pluginVersion><![CDATA[2.2.4.RELEASE]]></pluginVersion>
|
||||
<configSuffixes>
|
||||
<configSuffix><![CDATA[xml]]></configSuffix>
|
||||
</configSuffixes>
|
||||
@@ -59,6 +59,7 @@
|
||||
<config>src/test/resources/org/springframework/batch/core/configuration/xml/StopAndRestartJobParserTests-context.xml</config>
|
||||
<config>src/test/resources/org/springframework/batch/core/configuration/xml/StopRestartOnCompletedStepJobParserTests-context.xml</config>
|
||||
<config>src/test/resources/org/springframework/batch/core/configuration/xml/StopRestartOnFailedStepJobParserTests-context.xml</config>
|
||||
<config>src/test/resources/org/springframework/batch/core/configuration/xml/JobRegistryJobParserTests-context.xml</config>
|
||||
</configs>
|
||||
<configSets>
|
||||
<configSet>
|
||||
|
||||
@@ -59,7 +59,7 @@ public class JobParser extends AbstractSingleBeanDefinitionParser {
|
||||
protected void doParse(Element element, ParserContext parserContext, BeanDefinitionBuilder builder) {
|
||||
|
||||
CoreNamespaceUtils.autoregisterBeansForNamespace(parserContext, parserContext.extractSource(element));
|
||||
|
||||
|
||||
String jobName = element.getAttribute("id");
|
||||
builder.addConstructorArgValue(jobName);
|
||||
|
||||
|
||||
@@ -21,6 +21,7 @@ import org.springframework.batch.core.job.flow.Flow;
|
||||
import org.springframework.batch.core.job.flow.FlowJob;
|
||||
import org.springframework.batch.core.repository.JobRepository;
|
||||
import org.springframework.beans.factory.FactoryBean;
|
||||
import org.springframework.beans.factory.SmartFactoryBean;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
@@ -30,9 +31,10 @@ import org.springframework.util.StringUtils;
|
||||
* configurable on the <job/>.
|
||||
*
|
||||
* @author Dan Garrette
|
||||
* @author Dave Syer
|
||||
* @since 2.0.1
|
||||
*/
|
||||
class JobParserJobFactoryBean implements FactoryBean {
|
||||
class JobParserJobFactoryBean implements SmartFactoryBean {
|
||||
|
||||
private String name;
|
||||
|
||||
@@ -109,5 +111,13 @@ class JobParserJobFactoryBean implements FactoryBean {
|
||||
public boolean isSingleton() {
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean isEagerInit() {
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean isPrototype() {
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,55 @@
|
||||
/*
|
||||
* Copyright 2006-2007 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.batch.core.configuration.xml;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.batch.core.Job;
|
||||
import org.springframework.batch.core.configuration.ListableJobRegistry;
|
||||
import org.springframework.beans.BeansException;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.context.ApplicationContextAware;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
|
||||
/**
|
||||
* @author Dave Syer
|
||||
*
|
||||
*/
|
||||
@ContextConfiguration
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
public class JobRegistryJobParserTests implements ApplicationContextAware {
|
||||
|
||||
@Autowired
|
||||
private ListableJobRegistry jobRegistry;
|
||||
|
||||
private ApplicationContext applicationContext;
|
||||
|
||||
public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
|
||||
this.applicationContext = applicationContext;
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testOneStep() throws Exception {
|
||||
assertEquals(2, applicationContext.getBeanNamesForType(Job.class).length);
|
||||
assertEquals(2, jobRegistry.getJobNames().size());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<beans xmlns:batch="http://www.springframework.org/schema/batch"
|
||||
xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/batch http://www.springframework.org/schema/batch/spring-batch-2.0.xsd
|
||||
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd">
|
||||
|
||||
<bean id="transactionManager"
|
||||
class="org.springframework.batch.support.transaction.ResourcelessTransactionManager" />
|
||||
|
||||
<bean id="jobRepository"
|
||||
class="org.springframework.batch.core.repository.support.MapJobRepositoryFactoryBean">
|
||||
<property name="transactionManager" ref="transactionManager" />
|
||||
</bean>
|
||||
|
||||
<bean id="step1" class="org.springframework.batch.core.step.tasklet.TaskletStep">
|
||||
<property name="jobRepository" ref="jobRepository" />
|
||||
<property name="transactionManager" ref="transactionManager" />
|
||||
<property name="tasklet" ref="dummyTasklet" />
|
||||
</bean>
|
||||
|
||||
<bean id="dummyTasklet"
|
||||
class="org.springframework.batch.core.configuration.xml.DummyTasklet" />
|
||||
|
||||
<bean id="jobRegistry"
|
||||
class="org.springframework.batch.core.configuration.support.MapJobRegistry" />
|
||||
<bean
|
||||
class="org.springframework.batch.core.configuration.support.JobRegistryBeanPostProcessor">
|
||||
<property name="jobRegistry" ref="jobRegistry" />
|
||||
</bean>
|
||||
|
||||
<batch:job id="job2">
|
||||
<batch:step id="j2.s1" parent="step1" />
|
||||
</batch:job>
|
||||
|
||||
<batch:job id="job1" parent="job">
|
||||
<batch:step id="j1.s1" parent="step1" />
|
||||
</batch:job>
|
||||
|
||||
<bean id="job" class="org.springframework.batch.core.job.SimpleJob" abstract="true"/>
|
||||
|
||||
</beans>
|
||||
Reference in New Issue
Block a user