Victor / Dave,
I am still having problems with job params. Actually snicoll had few suggestions regarding my problem. I think I am following documentation / samples for most part. But I guess there is something that is still missing. Just to recap, I am using Batch 2.1.1, Spring 3.0, Java 5.0, STS 2.3.1. To simply things, I created a Simple Batch Job(different from original post) from STS template. My Module context looks like this
Code:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:batch="http://www.springframework.org/schema/batch"
xsi:schemaLocation="http://www.springframework.org/schema/batch http://www.springframework.org/schema/batch/spring-batch-2.1.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
<description>Example job to get you started. It provides a
skeleton for a typical batch application.</description>
<job id="job1" xmlns="http://www.springframework.org/schema/batch">
<step id="step1" parent="simpleStep">
<tasklet>
<chunk reader="reader" writer="writer"/>
</tasklet>
</step>
</job>
<bean class="org.springframework.batch.core.scope.StepScope" />
<bean id="reader" class="org.springframework.sample.batch.example.ExampleItemReader" scope="step">
<property name="secondInput" value="#{jobParameters['User']}"/>
</bean>
<bean id="writer" class="org.springframework.sample.batch.example.ExampleItemWriter" />
<bean id="simpleStep"
class="org.springframework.batch.core.step.item.SimpleStepFactoryBean"
abstract="true">
<property name="transactionManager" ref="transactionManager" />
<property name="jobRepository" ref="jobRepository" />
<property name="startLimit" value="100" />
<property name="commitInterval" value="1" />
</bean>
</beans>
As seen in config above reader needs to be passed a job variable for secondInput property.
The read method of Example ItemReader
Code:
public String read() throws Exception {
System.out.println("Second Input :" + secondInput);
...
}
My launch-context looks like this
Code:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:batch="http://www.springframework.org/schema/batch"
xsi:schemaLocation="http://www.springframework.org/schema/batch http://www.springframework.org/schema/batch/spring-batch-2.1.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
<import resource="classpath:/META-INF/spring/module-context.xml" />
<bean id="jobLauncher"
class="org.springframework.batch.core.launch.support.SimpleJobLauncher">
<property name="jobRepository" ref="jobRepository" />
</bean>
<batch:job-repository id="jobRepository" />
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource">
<property name="driverClassName" value="${batch.jdbc.driver}" />
<property name="url" value="${batch.jdbc.url}" />
<property name="username" value="${batch.jdbc.user}" />
<property name="password" value="${batch.jdbc.password}" />
</bean>
<bean id="transactionManager"
class="org.springframework.jdbc.datasource.DataSourceTransactionManager"
lazy-init="true">
<property name="dataSource" ref="dataSource" />
</bean>
<bean id="placeholderProperties"
class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="location" value="classpath:batch.properties" />
<property name="systemPropertiesModeName" value="SYSTEM_PROPERTIES_MODE_OVERRIDE" />
<property name="ignoreUnresolvablePlaceholders" value="true" />
<property name="order" value="1" />
</bean>
</beans>
My Test Class for testing launcher is
Code:
@ContextConfiguration(locations={"/launch-context.xml"})
@RunWith(SpringJUnit4ClassRunner.class)
public class ExampleJobConfigurationTests {
@Autowired
JobLauncher jobLauncher;
@Autowired
Job job;
@Test
public void testLaunchJob() throws Exception {
JobParametersBuilder jpBuilder = new JobParametersBuilder();
jpBuilder.addDate("currentTime", new Date());
jpBuilder.addString("User", "Sample");
jobLauncher.run(job, jpBuilder.toJobParameters());
}
}
I see the stack trace as follows (part of it)
Code:
...
2010-04-28 17:11:12,327 DEBUG [org.springframework.batch.core.step.AbstractStep] - <Executing: id=28>
2010-04-28 17:11:12,405 DEBUG [org.springframework.batch.repeat.support.RepeatTemplate] - <Starting repeat context.>
2010-04-28 17:11:12,405 DEBUG [org.springframework.batch.repeat.support.RepeatTemplate] - <Repeat operation about to start at count=1>
2010-04-28 17:11:12,405 DEBUG [org.springframework.batch.core.scope.context.StepContextRepeatCallback] - <Preparing chunk execution for StepContext: org.springframework.batch.core.scope.context.StepContext@1e67e6a>
2010-04-28 17:11:12,405 DEBUG [org.springframework.batch.core.scope.context.StepContextRepeatCallback] - <Chunk execution starting: queue size=0>
2010-04-28 17:11:12,405 DEBUG [org.springframework.batch.repeat.support.RepeatTemplate] - <Starting repeat context.>
2010-04-28 17:11:12,405 DEBUG [org.springframework.batch.repeat.support.RepeatTemplate] - <Repeat operation about to start at count=1>
2010-04-28 17:11:12,405 DEBUG [org.springframework.batch.core.scope.StepScope] - <Creating object in scope=step, name=scopedTarget.scopedTarget.reader>
Second Input :#{jobParameters['User']}
2010-04-28 17:11:12,405 DEBUG [org.springframework.batch.repeat.support.RepeatTemplate] - <Repeat is complete according to policy and result value.>
######[Hello World!#{jobParameters['User']}]-null
...
Even though I have not been spending all my time on this, I have had this issue for sometime. Any help to fix my problem would be helpful. I am sure I am overseeing something little detail.
Thanks