In our implementation, Job is described as:
Code:
<job id="myJob" restartable="true">
<step id="step1">
<tasklet task-executor="taskExecutor">
<chunk reader="readerFactory"
processor="processorFactory"
writer="writerFactory"
commit-interval="1000"/>
<listeners>
<listener ref="stepListener" />
</listeners>
</tasklet>
</step>
<listeners>
<listener ref="jobListener"/>
</listeners>
</job>
and the 'readerFactory' above is described as:
Code:
<bean id="ReaderFactory" class="com.mycompany.batch.ReaderFactory" scope="step">
<!--
pass in parameters required to construct and initialize the
required reader. In my code I passed in the id of a spring
bean defined elsewhere, and parameters required to initialize
that bean.
-->
<property name="reader" value="#{jobParameters[input.itemReader]}"/>
<property name="resource" value="#{jobParameters[input.file.name]}"/>
<property name="format" value="#{jobParameters[job.input.format]}" />
</bean>
and 'ReaderFactory' is a Spring FactoryBean class, defined as:
Code:
public class ReaderFactory implements ApplicationContextAware, FactoryBean {
protected ApplicationContext applicationContext;
protected String reader;
protected String resource;
protected Format format; //provides format (fixedWidth, delimited etc.,
//and other detailed mapping information such as
//column names and ranges, also if header/footer is
//present, wether multi-line etc.
public Class getObjectType() {
return AbstractItemCountingItemStreamItemReader.class;
}
public boolean isSingleton() {
return false;
}
public Object getObject() {
// Construct, initialize and return the reader
}
}
In our implementation, 'reader' above is the id of a spring bean defined elsewhere. Using 'applicationContext', the reader bean is obtained and is initialized using the parameters provided.
I hope this is helpful. Thanks.