Add ability to set a custom TaskExecutor impl, remove unused namespaces from JSR bootstrap XML files
This commit is contained in:
committed by
Michael Minella
parent
8580756857
commit
65d2df652a
@@ -49,6 +49,7 @@ import org.springframework.batch.core.jsr.JsrJobParametersConverter;
|
||||
import org.springframework.batch.core.jsr.configuration.support.BatchPropertyContext;
|
||||
import org.springframework.batch.core.jsr.configuration.support.ThreadLocalClassloaderBeanPostProcessor;
|
||||
import org.springframework.batch.core.repository.JobRepository;
|
||||
import org.springframework.beans.factory.InitializingBean;
|
||||
import org.springframework.beans.factory.access.BeanFactoryLocator;
|
||||
import org.springframework.beans.factory.access.BeanFactoryReference;
|
||||
import org.springframework.beans.factory.config.AutowireCapableBeanFactory;
|
||||
@@ -116,7 +117,7 @@ import org.springframework.util.Assert;
|
||||
* @author Chris Schaefer
|
||||
* @since 3.0
|
||||
*/
|
||||
public class JsrJobOperator implements JobOperator {
|
||||
public class JsrJobOperator implements JobOperator, InitializingBean {
|
||||
private static final String BATCH_PROPERTY_CONTEXT_BEAN_NAME = "batchPropertyContext";
|
||||
|
||||
private org.springframework.batch.core.launch.JobOperator batchJobOperator;
|
||||
@@ -183,6 +184,21 @@ public class JsrJobOperator implements JobOperator {
|
||||
this.batchJobOperator = jobOperator;
|
||||
}
|
||||
|
||||
public void setTaskExecutor(TaskExecutor taskExecutor) {
|
||||
this.taskExecutor = taskExecutor;
|
||||
}
|
||||
|
||||
protected TaskExecutor getTaskExecutor() {
|
||||
return taskExecutor;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void afterPropertiesSet() throws Exception {
|
||||
if (this.taskExecutor == null) {
|
||||
this.taskExecutor = new SyncTaskExecutor();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Used to convert the {@link Properties} objects used by JSR-352 to the {@link JobParameters}
|
||||
* objects used in Spring Batch. The default implementation used will configure all parameters
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||
xmlns:context="http://www.springframework.org/schema/context"
|
||||
xmlns:batch="http://www.springframework.org/schema/batch"
|
||||
xmlns:jdbc="http://www.springframework.org/schema/jdbc"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
@@ -9,9 +8,7 @@
|
||||
http://www.springframework.org/schema/batch
|
||||
http://www.springframework.org/schema/batch/spring-batch.xsd
|
||||
http://www.springframework.org/schema/jdbc
|
||||
http://www.springframework.org/schema/jdbc/spring-jdbc-3.2.xsd
|
||||
http://www.springframework.org/schema/context
|
||||
http://www.springframework.org/schema/context/spring-context-3.2.xsd">
|
||||
http://www.springframework.org/schema/jdbc/spring-jdbc.xsd">
|
||||
|
||||
<batch:job-repository data-source="dataSource" id="jobRepository"
|
||||
transaction-manager="transactionManager" table-prefix="BATCH_"/>
|
||||
|
||||
@@ -1,17 +1,8 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||
xmlns:context="http://www.springframework.org/schema/context"
|
||||
xmlns:batch="http://www.springframework.org/schema/batch"
|
||||
xmlns:jdbc="http://www.springframework.org/schema/jdbc"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans
|
||||
http://www.springframework.org/schema/beans/spring-beans.xsd
|
||||
http://www.springframework.org/schema/batch
|
||||
http://www.springframework.org/schema/batch/spring-batch.xsd
|
||||
http://www.springframework.org/schema/jdbc
|
||||
http://www.springframework.org/schema/jdbc/spring-jdbc-3.2.xsd
|
||||
http://www.springframework.org/schema/context
|
||||
http://www.springframework.org/schema/context/spring-context-3.2.xsd">
|
||||
http://www.springframework.org/schema/beans/spring-beans.xsd">
|
||||
|
||||
<bean id="baseContext" class="org.springframework.context.support.GenericXmlApplicationContext">
|
||||
<constructor-arg>
|
||||
@@ -20,5 +11,4 @@
|
||||
</list>
|
||||
</constructor-arg>
|
||||
</bean>
|
||||
|
||||
</beans>
|
||||
|
||||
@@ -41,6 +41,8 @@ import org.springframework.batch.core.jsr.JsrJobParametersConverter;
|
||||
import org.springframework.batch.core.launch.support.SimpleJobOperator;
|
||||
import org.springframework.batch.core.repository.JobRepository;
|
||||
import org.springframework.batch.core.step.JobRepositorySupport;
|
||||
import org.springframework.core.task.SimpleAsyncTaskExecutor;
|
||||
import org.springframework.core.task.SyncTaskExecutor;
|
||||
|
||||
public class JsrJobOperatorTests {
|
||||
|
||||
@@ -95,6 +97,23 @@ public class JsrJobOperatorTests {
|
||||
new JsrJobOperator(new SimpleJobExplorer(null, null, null, null), new JobRepositorySupport(), new SimpleJobOperator(), parameterConverter);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDefaultTaskExecutor() throws Exception {
|
||||
JsrJobOperator jsrJobOperatorImpl = (JsrJobOperator) jsrJobOperator;
|
||||
jsrJobOperatorImpl.afterPropertiesSet();
|
||||
assertNotNull(jsrJobOperatorImpl.getTaskExecutor());
|
||||
assertTrue((jsrJobOperatorImpl.getTaskExecutor() instanceof SyncTaskExecutor));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCustomTaskExecutor() throws Exception {
|
||||
JsrJobOperator jsrJobOperatorImpl = (JsrJobOperator) jsrJobOperator;
|
||||
jsrJobOperatorImpl.setTaskExecutor(new SimpleAsyncTaskExecutor());
|
||||
jsrJobOperatorImpl.afterPropertiesSet();
|
||||
assertNotNull(jsrJobOperatorImpl.getTaskExecutor());
|
||||
assertTrue((jsrJobOperatorImpl.getTaskExecutor() instanceof SimpleAsyncTaskExecutor));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAbandonRoseyScenario() throws Exception {
|
||||
JobExecution jobExecution = new JobExecution(5l);
|
||||
|
||||
Reference in New Issue
Block a user