Refactor samples to use child context (useful for JMX demo as well).

This commit is contained in:
dsyer
2007-11-09 11:20:58 +00:00
parent e0977c3e48
commit 9a7ffaaf22
19 changed files with 261 additions and 259 deletions

View File

@@ -1,8 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<beansProjectDescription>
<configExtensions>
<configExtension>xml</configExtension>
</configExtensions>
<version>1</version>
<pluginVersion><![CDATA[2.0.2.v200710312100]]></pluginVersion>
<configSuffixes>
<configSuffix><![CDATA[xml]]></configSuffix>
</configSuffixes>
<configs>
<config>src/main/resources/jobs/fixedLengthImportJob.xml</config>
<config>src/main/resources/jobs/multilineJob.xml</config>
@@ -25,7 +27,7 @@
<config>src/main/resources/jobs/compositeProcessorSampleJob.xml</config>
<config>src/main/resources/jobs/nflJob.xml</config>
<config>src/main/resources/jobs/simpleTaskletJob.xml</config>
<config>src/main/resources/beanRefContext.xml</config>
<config>src/main/resources/beanRefContext.xml</config>
</configs>
<configSets>
<configSet>
@@ -151,5 +153,15 @@
<config>src/main/resources/jobs/nflJob.xml</config>
</configs>
</configSet>
<configSet>
<name><![CDATA[simpleTasklet]]></name>
<allowBeanDefinitionOverriding>true</allowBeanDefinitionOverriding>
<incomplete>false</incomplete>
<configs>
<config>src/main/resources/data-source-context.xml</config>
<config>src/main/resources/jobs/simpleTaskletJob.xml</config>
<config>src/main/resources/simple-container-definition.xml</config>
</configs>
</configSet>
</configSets>
</beansProjectDescription>

View File

@@ -7,50 +7,22 @@
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-2.0.xsd">
<!-- The module used in this job will run in an infinite loop. This is useful for testing graceful shutdown from
<!-- The tasklet used in this job will run in an infinite loop. This is useful for testing graceful shutdown from
multiple environments. -->
<import resource="../simple-container-definition.xml" />
<bean parent="stepScope"/>
<bean parent="jobConfigurationRegistryBeanPostProcessor"/>
<bean
class="org.springframework.batch.execution.configuration.JobConfigurationRegistryBeanPostProcessor">
<property name="jobConfigurationRegistry"
ref="jobConfigurationRegistry" />
</bean>
<bean id="jobLauncher"
class="org.springframework.batch.execution.launch.SimpleJobLauncher">
<property name="jobRepository" ref="simpleJobRepository" />
<property name="jobConfigurationLocator" ref="jobConfigurationRegistry"/>
<property name="jobExecutor">
<bean parent="jobExecutor">
<property name="stepExecutorFactory">
<bean
class="org.springframework.batch.execution.step.PrototypeBeanStepExecutorFactory">
<property name="stepExecutorName"
value="notifyingStepExecutor" />
</bean>
</property>
</bean>
</property>
<property name="taskExecutor">
<bean
class="org.springframework.core.task.SimpleAsyncTaskExecutor" />
</property>
<property name="autoStart" value="false" />
<property name="jobConfigurationName" value="jobConfiguration"/>
</bean>
<bean id="jobConfiguration" parent="simpleJob">
<bean id="loopJob" parent="simpleJob">
<property name="steps">
<bean id="step1" parent="simpleStep">
<constructor-arg>
<property name="tasklet">
<bean id="module"
class="org.springframework.batch.sample.tasklet.InfiniteLoopTasklet"
scope="step">
<aop:scoped-proxy />
</bean>
</constructor-arg>
</property>
<property name="commitInterval" value="2" />
</bean>
</property>
@@ -118,4 +90,27 @@
</aop:aspect>
</aop:config>
<bean id="jobLauncher"
class="org.springframework.batch.execution.launch.SimpleJobLauncher">
<property name="jobRepository" ref="simpleJobRepository" />
<property name="jobConfigurationLocator" ref="jobConfigurationRegistry"/>
<property name="jobExecutor">
<bean parent="jobExecutor">
<property name="stepExecutorFactory">
<bean
class="org.springframework.batch.execution.step.PrototypeBeanStepExecutorFactory">
<property name="stepExecutorName"
value="notifyingStepExecutor" />
</bean>
</property>
</bean>
</property>
<property name="taskExecutor">
<bean
class="org.springframework.core.task.SimpleAsyncTaskExecutor" />
</property>
<property name="autoStart" value="false" />
<property name="jobConfigurationName" value="loopJob"/>
</bean>
</beans>

View File

@@ -7,15 +7,14 @@
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.0.xsd">
<bean class="org.springframework.batch.execution.configuration.JobConfigurationRegistryBeanPostProcessor">
<property name="jobConfigurationRegistry" ref="jobConfigurationRegistry"/>
</bean>
<bean parent="stepScope"/>
<bean parent="jobConfigurationRegistryBeanPostProcessor"/>
<bean id="jobConfiguration" parent="simpleJob">
<property name="steps">
<list>
<bean id="step1" parent="simpleStep">
<constructor-arg>
<property name="tasklet">
<bean
class="org.springframework.batch.execution.tasklet.RestartableItemProviderTasklet">
<property name="itemProvider">
@@ -31,10 +30,10 @@
</bean>
</property>
</bean>
</constructor-arg>
</property>
</bean>
<bean id="step2" parent="simpleStep">
<constructor-arg>
<property name="tasklet">
<bean
class="org.springframework.batch.execution.tasklet.RestartableItemProviderTasklet">
<property name="itemProvider">
@@ -47,7 +46,7 @@
<bean class="org.springframework.batch.sample.item.processor.PersonProcessor" />
</property>
</bean>
</constructor-arg>
</property>
</bean>
</list>

View File

@@ -7,14 +7,13 @@
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.0.xsd">
<bean class="org.springframework.batch.execution.configuration.JobConfigurationRegistryBeanPostProcessor">
<property name="jobConfigurationRegistry" ref="jobConfigurationRegistry"/>
</bean>
<bean parent="stepScope"/>
<bean parent="jobConfigurationRegistryBeanPostProcessor"/>
<bean id="jobConfiguration" parent="simpleJob">
<property name="steps">
<bean id="step1" parent="simpleStep">
<constructor-arg>
<property name="tasklet">
<bean
class="org.springframework.batch.execution.tasklet.RestartableItemProviderTasklet">
<property name="itemProvider">
@@ -40,7 +39,7 @@
</bean>
</property>
</bean>
</constructor-arg>
</property>
</bean>
</property>
</bean>

View File

@@ -7,9 +7,8 @@
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.0.xsd">
<bean class="org.springframework.batch.execution.configuration.JobConfigurationRegistryBeanPostProcessor">
<property name="jobConfigurationRegistry" ref="jobConfigurationRegistry"/>
</bean>
<bean parent="stepScope"/>
<bean parent="jobConfigurationRegistryBeanPostProcessor"/>
<bean id="jobConfiguration" parent="simpleJob">
<property name="steps">

View File

@@ -11,9 +11,8 @@
Example for Hibernate integration.
</description>
<bean class="org.springframework.batch.execution.configuration.JobConfigurationRegistryBeanPostProcessor">
<property name="jobConfigurationRegistry" ref="jobConfigurationRegistry"/>
</bean>
<bean parent="stepScope"/>
<bean parent="jobConfigurationRegistryBeanPostProcessor"/>
<bean id="jobConfiguration" parent="simpleJob">
<property name="steps">

View File

@@ -11,12 +11,10 @@
Example for iBATIS integration.
</description>
<bean parent="stepScope"/>
<bean parent="jobConfigurationRegistryBeanPostProcessor"/>
<bean class="org.springframework.batch.execution.configuration.JobConfigurationRegistryBeanPostProcessor">
<property name="jobConfigurationRegistry" ref="jobConfigurationRegistry"/>
</bean>
<bean id="jobConfiguration" parent="simpleJob">
<bean id="ibatisJob" parent="simpleJob">
<property name="steps">
<bean id="step1" parent="simpleStep">
<property name="tasklet">

View File

@@ -6,12 +6,11 @@
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-2.0.xsd">
<!-- The module used in this job will run in an infinite loop. This is useful for testing graceful shutdown from
<!-- The tasklet used in this job will run in an infinite loop. This is useful for testing graceful shutdown from
multiple environments. -->
<bean class="org.springframework.batch.execution.configuration.JobConfigurationRegistryBeanPostProcessor">
<property name="jobConfigurationRegistry" ref="jobConfigurationRegistry"/>
</bean>
<bean parent="stepScope"/>
<bean parent="jobConfigurationRegistryBeanPostProcessor"/>
<!-- Override the default jobExecutorFacade to provide a listener that can interrupt the job -->
<bean id="jobExecutorFacade" class="org.springframework.batch.execution.launch.SimpleJobExecutorFacade">
@@ -29,9 +28,9 @@
<bean id="jobConfiguration" parent="simpleJob">
<property name="steps">
<bean id="step1" parent="simpleStep">
<constructor-arg>
<property name="tasklet">
<bean id="module" class="org.springframework.batch.sample.tasklet.InfiniteLoopTasklet"/>
</constructor-arg>
</property>
<property name="commitInterval" value="2" />
</bean>
</property>

View File

@@ -7,16 +7,13 @@
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-2.0.xsd">
<bean
class="org.springframework.batch.execution.configuration.JobConfigurationRegistryBeanPostProcessor">
<property name="jobConfigurationRegistry"
ref="jobConfigurationRegistry" />
</bean>
<bean parent="stepScope"/>
<bean parent="jobConfigurationRegistryBeanPostProcessor"/>
<bean id="jobConfiguration" parent="simpleJob">
<property name="steps">
<bean id="step1" parent="simpleStep">
<constructor-arg>
<property name="tasklet">
<bean
class="org.springframework.batch.execution.tasklet.RestartableItemProviderTasklet">
<property name="itemProvider">
@@ -41,7 +38,7 @@
</bean>
</property>
</bean>
</constructor-arg>
</property>
</bean>
</property>
</bean>

View File

@@ -10,12 +10,10 @@
<import resource="multilineOrderOutputDescriptors.xml" />
<import resource="multilineOrderIo.xml" />
<bean
class="org.springframework.batch.execution.configuration.JobConfigurationRegistryBeanPostProcessor">
<property name="jobConfigurationRegistry" ref="jobConfigurationRegistry" />
</bean>
<bean parent="stepScope"/>
<bean parent="jobConfigurationRegistryBeanPostProcessor"/>
<bean id="jobConfiguration" parent="simpleJob">
<bean id="multilineOrderJob" parent="simpleJob">
<property name="steps">
<bean id="step1" parent="simpleStep">
<property name="tasklet">

View File

@@ -1,15 +1,18 @@
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:p="http://www.springframework.org/schema/p"
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-2.0.xsd">
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.0.xsd">
<bean
class="org.springframework.batch.execution.configuration.JobConfigurationRegistryBeanPostProcessor">
<property name="jobConfigurationRegistry"
ref="jobConfigurationRegistry" />
</bean>
<bean parent="stepScope" />
<bean parent="jobConfigurationRegistryBeanPostProcessor" />
<bean id="nfljob"
<bean id="nflJob"
class="org.springframework.batch.core.configuration.JobConfiguration">
<property name="restartable" value="true" />
<property name="startLimit" value="100" />
@@ -37,7 +40,8 @@
<property name="nflPlayerDao">
<bean
class="org.springframework.batch.sample.dao.SqlNflPlayerDao">
<property name="dataSource" ref="dataSource" />
<property name="dataSource"
ref="dataSource" />
</bean>
</property>
</bean>
@@ -169,4 +173,15 @@
</value>
</property>
</bean>
<aop:config>
<aop:aspect id="moduleLogging" ref="itemProcessorLogAdvice">
<aop:after
pointcut="execution( * org.springframework.batch.item.ItemProcessor+.process(Object)) and args(item)"
method="doStronglyTypedLogging" />
</aop:aspect>
</aop:config>
</beans>

View File

@@ -7,9 +7,9 @@
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.0.xsd">
<bean class="org.springframework.batch.execution.configuration.JobConfigurationRegistryBeanPostProcessor">
<property name="jobConfigurationRegistry" ref="jobConfigurationRegistry"/>
</bean>
<bean parent="stepScope"/>
<bean parent="jobConfigurationRegistryBeanPostProcessor"/>
<bean parent="customEditorConfigurer"/>
<bean id="restartSample" parent="simpleJob">
<property name="steps">
@@ -36,8 +36,6 @@
</property>
</bean>
<!-- INFRASTRUCTURE SETUP -->
<bean id="fileInputSource" class="org.springframework.batch.io.file.support.DefaultFlatFileInputSource"
@@ -84,5 +82,4 @@
<bean id="fieldSetMapper" class="org.springframework.batch.sample.mapping.TradeFieldSetMapper" />
</beans>

View File

@@ -7,24 +7,21 @@
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-2.0.xsd">
<bean
class="org.springframework.batch.execution.configuration.JobConfigurationRegistryBeanPostProcessor">
<property name="jobConfigurationRegistry"
ref="jobConfigurationRegistry" />
</bean>
<bean parent="stepScope"/>
<bean parent="jobConfigurationRegistryBeanPostProcessor"/>
<bean id="simpleTrade" parent="simpleJob">
<bean id="simpleTaskletJob" parent="simpleJob">
<property name="steps">
<list>
<bean id="step1" parent="simpleStep">
<constructor-arg>
<property name="tasklet">
<bean id="tradeTasklet"
class="org.springframework.batch.sample.tasklet.SimpleTradeTasklet">
<property name="inputSource"
ref="fileInputSource" />
<property name="tradeDao" ref="tradeDao" />
</bean>
</constructor-arg>
</property>
<property name="commitInterval" value="2" />
</bean>
</list>

View File

@@ -9,13 +9,9 @@
http://www.springframework.org/schema/aop/spring-aop-2.0.xsd">
<import resource="tradeJobIo.xml" />
<!--import resource="tradeJobAop.xml" /-->
<bean
class="org.springframework.batch.execution.configuration.JobConfigurationRegistryBeanPostProcessor">
<property name="jobConfigurationRegistry"
ref="jobConfigurationRegistry" />
</bean>
<bean parent="stepScope"/>
<bean parent="jobConfigurationRegistryBeanPostProcessor"/>
<bean id="tradeJob" parent="simpleJob">
<property name="steps">

View File

@@ -9,14 +9,13 @@
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.0.xsd
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-2.0.xsd">
<bean class="org.springframework.batch.execution.configuration.JobConfigurationRegistryBeanPostProcessor">
<property name="jobConfigurationRegistry" ref="jobConfigurationRegistry"/>
</bean>
<bean parent="stepScope"/>
<bean parent="jobConfigurationRegistryBeanPostProcessor"/>
<bean id="xmlStaxJob" parent="simpleJob">
<property name="steps">
<bean id="step1" parent="simpleStep">
<constructor-arg>
<property name="tasklet">
<bean
class="org.springframework.batch.execution.tasklet.RestartableItemProviderTasklet">
<property name="itemProvider">
@@ -45,7 +44,7 @@
p:outputSource-ref="tradeStaxWriter" />
</property>
</bean>
</constructor-arg>
</property>
</bean>
</property>
</bean>

View File

@@ -1,6 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx" xmlns:p="http://www.springframework.org/schema/p"
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:p="http://www.springframework.org/schema/p"
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-2.0.xsd
@@ -10,18 +12,29 @@
<import resource="data-source-context.xml" />
<!-- register the step scope with the application context -->
<bean id="stepScope" class="org.springframework.batch.execution.scope.StepScope" />
<bean id="stepScope"
class="org.springframework.batch.execution.scope.StepScope" />
<bean id="jobLauncher" class="org.springframework.batch.execution.launch.SimpleJobLauncher">
<bean id="jobConfigurationRegistryBeanPostProcessor"
class="org.springframework.batch.execution.configuration.JobConfigurationRegistryBeanPostProcessor">
<property name="jobConfigurationRegistry"
ref="jobConfigurationRegistry" />
</bean>
<bean id="jobLauncher"
class="org.springframework.batch.execution.launch.SimpleJobLauncher">
<property name="jobRepository" ref="simpleJobRepository" />
<property name="jobConfigurationLocator" ref="jobConfigurationRegistry"/>
<property name="jobConfigurationLocator"
ref="jobConfigurationRegistry" />
<property name="jobExecutor" ref="jobExecutor" />
</bean>
<bean id="jobConfigurationRegistry" class="org.springframework.batch.execution.configuration.MapJobConfigurationRegistry"/>
<bean id="jobConfigurationRegistry"
class="org.springframework.batch.execution.configuration.MapJobConfigurationRegistry" />
<aop:config>
<aop:advisor pointcut="execution(* org.springframework.batch.execution..*Repository+.*(..))"
<aop:advisor
pointcut="execution(* org.springframework.batch.execution..*Repository+.*(..))"
advice-ref="txAdvice" />
</aop:config>
@@ -31,37 +44,45 @@
</tx:attributes>
</tx:advice>
<bean id="jobExecutor" class="org.springframework.batch.execution.job.DefaultJobExecutor">
<bean id="jobExecutor"
class="org.springframework.batch.execution.job.DefaultJobExecutor">
<property name="jobRepository" ref="simpleJobRepository" />
<property name="stepExecutorFactory">
<bean class="org.springframework.batch.execution.step.PrototypeBeanStepExecutorFactory">
<bean
class="org.springframework.batch.execution.step.PrototypeBeanStepExecutorFactory">
<property name="stepExecutorName" value="stepExecutor" />
</bean>
</property>
</bean>
<bean id="stepExecutor" class="org.springframework.batch.execution.step.simple.SimpleStepExecutor"
<bean id="stepExecutor"
class="org.springframework.batch.execution.step.simple.SimpleStepExecutor"
scope="prototype">
<property name="transactionManager" ref="transactionManager" />
<property name="repository" ref="simpleJobRepository" />
</bean>
<bean id="simpleJobRepository" class="org.springframework.batch.execution.repository.SimpleJobRepository">
<bean id="simpleJobRepository"
class="org.springframework.batch.execution.repository.SimpleJobRepository">
<constructor-arg ref="jobDao" />
<constructor-arg ref="stepDao" />
</bean>
<bean id="jobDao" class="org.springframework.batch.execution.repository.dao.SqlJobDao">
<bean id="jobDao"
class="org.springframework.batch.execution.repository.dao.SqlJobDao">
<property name="jdbcTemplate" ref="jdbcTemplate" />
<property name="jobIncrementer" ref="jobIncrementer" />
<property name="jobExecutionIncrementer" ref="jobExecutionIncrementer" />
<property name="jobExecutionIncrementer"
ref="jobExecutionIncrementer" />
</bean>
<bean id="stepDao" class="org.springframework.batch.execution.repository.dao.SqlStepDao">
<bean id="stepDao"
class="org.springframework.batch.execution.repository.dao.SqlStepDao">
<property name="jdbcTemplate" ref="jdbcTemplate" />
<property name="stepIncrementer" ref="stepIncrementer" />
<property name="stepExecutionIncrementer" ref="stepExecutionIncrementer" />
<property name="jobDao" ref="jobDao"/>
<property name="stepExecutionIncrementer"
ref="stepExecutionIncrementer" />
<property name="jobDao" ref="jobDao" />
</bean>
<bean id="jobRuntimeInformationFactory"
@@ -71,16 +92,19 @@
<property name="jobRun" value="1" />
</bean>
<bean id="jdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate">
<bean id="jdbcTemplate"
class="org.springframework.jdbc.core.JdbcTemplate">
<property name="dataSource" ref="dataSource" />
</bean>
<bean id="simpleJob" class="org.springframework.batch.core.configuration.JobConfiguration"
<bean id="simpleJob"
class="org.springframework.batch.core.configuration.JobConfiguration"
abstract="true">
<property name="restartable" value="true" />
</bean>
<bean id="simpleStep" class="org.springframework.batch.execution.step.SimpleStepConfiguration"
<bean id="simpleStep"
class="org.springframework.batch.execution.step.SimpleStepConfiguration"
abstract="true">
<property name="allowStartIfComplete" value="true" />
<property name="saveRestartData" value="false" />
@@ -88,23 +112,28 @@
<bean
class="org.springframework.batch.repeat.exception.handler.SimpleLimitExceptionHandler">
<property name="limit" value="5" />
<property name="useParent" value="true"/>
<property name="useParent" value="true" />
</bean>
</property>
<property name="commitInterval" value="1" />
</bean>
<bean id="customEditorConfigurer" class="org.springframework.beans.factory.config.CustomEditorConfigurer">
<bean id="customEditorConfigurer"
class="org.springframework.beans.factory.config.CustomEditorConfigurer">
<property name="customEditors">
<map>
<entry key="int[]">
<bean class="org.springframework.batch.support.IntArrayPropertyEditor" />
<bean
class="org.springframework.batch.support.IntArrayPropertyEditor" />
</entry>
<entry key="org.springframework.batch.io.file.support.transform.Range[]">
<bean class="org.springframework.batch.io.file.support.transform.RangeArrayPropertyEditor" />
<entry
key="org.springframework.batch.io.file.support.transform.Range[]">
<bean
class="org.springframework.batch.io.file.support.transform.RangeArrayPropertyEditor" />
</entry>
<entry key="java.util.Date">
<bean class="org.springframework.beans.propertyeditors.CustomDateEditor">
<bean
class="org.springframework.beans.propertyeditors.CustomDateEditor">
<constructor-arg>
<bean class="java.text.SimpleDateFormat">
<constructor-arg value="yyyyMMdd" />
@@ -117,7 +146,8 @@
</property>
</bean>
<bean id="itemProcessorLogAdvice" class="org.springframework.batch.sample.advice.ProcessorLogAdvice" />
<bean id="itemProcessorLogAdvice"
class="org.springframework.batch.sample.advice.ProcessorLogAdvice" />
<aop:config>
<aop:aspect id="moduleLogging" ref="itemProcessorLogAdvice">

View File

@@ -1,54 +0,0 @@
/*
* 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.sample;
import org.springframework.batch.core.configuration.JobConfiguration;
import org.springframework.batch.execution.launch.JobLauncher;
import org.springframework.test.AbstractDependencyInjectionSpringContextTests;
/**
* Abstract unit test for running functional tests by getting context locations for
* both the container and configuration separately and having them auto wired in
* by type. This allows the two to be completely separated, and remove any
* 'configuration coupling' between the two. However, it is still purely
* theoretical until a decision is made as to how job configuration and container
* configuration files are pulled together.
*
* @author Lucas Ward
*
*/
public abstract class AbstractBatchBootstrapSpringContextTests extends AbstractDependencyInjectionSpringContextTests {
private static final String CONTAINER_DEFINITION_LOCATION = "simple-container-definition.xml";
JobLauncher launcher;
JobConfiguration jobConfiguration;
protected String[] getConfigLocations() {
return new String[]{CONTAINER_DEFINITION_LOCATION, getJobConfigurationContextLocation()};
}
public void testLifecycle() throws Exception {
launcher.run();
}
public void setLauncher(JobLauncher bootstrap){
this.launcher = bootstrap;
}
protected abstract String getJobConfigurationContextLocation();
}

View File

@@ -1,64 +1,69 @@
/*
* 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.sample;
import org.springframework.batch.core.configuration.JobConfiguration;
import org.springframework.batch.execution.launch.JobLauncher;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.test.AbstractDependencyInjectionSpringContextTests;
/**
* @author Dave Syer
*
*/
public abstract class AbstractBatchLauncherTests extends AbstractDependencyInjectionSpringContextTests {
protected JobLauncher launcher;
private JobConfiguration jobConfiguration;
protected ConfigurableApplicationContext createApplicationContext(
String[] locations) {
String[] allLocations = new String[locations.length+1];
System.arraycopy(locations, 0, allLocations, 1, locations.length);
allLocations[0] = "simple-container-definition.xml";
return super.createApplicationContext(allLocations);
}
/**
* Subclasses can provide name of job to run. We guess it by looking at the
* unique job configuration name.
*/
protected String getJobName() {
return jobConfiguration.getName();
}
/**
* @param jobConfiguration the jobConfiguration to set
*/
public void setJobConfiguration(JobConfiguration jobConfiguration) {
this.jobConfiguration = jobConfiguration;
}
/**
* Public setter for the {@link JobLauncher} property.
*
* @param launcher the launcher to set
*/
public void setLauncher(JobLauncher launcher) {
this.launcher = launcher;
}
}
/*
* 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.sample;
import org.springframework.batch.core.configuration.JobConfiguration;
import org.springframework.batch.execution.launch.JobLauncher;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.test.AbstractDependencyInjectionSpringContextTests;
/**
* Abstract unit test for running functional tests by getting context locations for
* both the container and configuration separately and having them auto wired in
* by type. This allows the two to be completely separated, and remove any
* 'configuration coupling' between the two. However, it is still purely
* theoretical until a decision is made as to how job configuration and container
* configuration files are pulled together.
*
* @author Lucas Ward
*
*/
public abstract class AbstractBatchLauncherTests extends AbstractDependencyInjectionSpringContextTests {
private static final String CONTAINER_DEFINITION_LOCATION = "simple-container-definition.xml";
JobLauncher launcher;
JobConfiguration jobConfiguration;
/* (non-Javadoc)
* @see org.springframework.test.AbstractSingleSpringContextTests#createApplicationContext(java.lang.String[])
*/
protected ConfigurableApplicationContext createApplicationContext(
String[] locations) {
ApplicationContext parent = new ClassPathXmlApplicationContext(CONTAINER_DEFINITION_LOCATION);
return new ClassPathXmlApplicationContext(locations, parent);
}
public void setLauncher(JobLauncher bootstrap){
this.launcher = bootstrap;
}
/**
* Public setter for the {@link JobConfiguration} property.
*
* @param jobConfiguration the jobConfiguration to set
*/
public void setJobConfiguration(JobConfiguration jobConfiguration) {
this.jobConfiguration = jobConfiguration;
}
protected String getJobName() {
return jobConfiguration.getName();
}
}

View File

@@ -15,21 +15,43 @@
*/
package org.springframework.batch.sample;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
/**
* @author Dave Syer
*
*
*/
public class TaskExecutorLauncher {
public static void main(String[] args) throws Exception {
final String path = "jobs/adhocLoopJob.xml";
// Paths to individual job configurations. Each one must include the
// step scope and the jobConfigurationRegistryBeanPostProcessor.
final String[] paths = new String[] { "jobs/adhocLoopJob.xml",
"jobs/nflJob.xml" };
// The simple execution environment will be used as a parent
// context for each of the job contexts. The standard version of this
// from the Spring Batch samples does not have an MBean for the
// JobLauncher, nor does the JobLauncher have an asynchronous
// TaskExecutor. The adhocLoopJob has both, which is why it has to be
// included in the paths above.
final ApplicationContext parent = new ClassPathXmlApplicationContext(
"simple-container-definition.xml");
new Thread(new Runnable() {
public void run() {
new ClassPathXmlApplicationContext(path);
for (int i = 0; i < paths.length; i++) {
String path = paths[i];
new ClassPathXmlApplicationContext(new String[] { path },
parent);
}
};
}).start();
System.out.println("Started application. Please connect using JMX.");
System.in.read();
}
}