Spring Batch CommandRunner and XML
org.springframework.batch.core.launch.support.CommandLineJobRunner
This is legacy way to run spring batch program.
The simple way to make program and run spring batch program is Spring Batch Get Started.
If you are not familiar with Spring Application with gradle please read Spring Boot Gradle
Config is Configuration class.(with Annotation)
To run with CommandLineJobRunner, we need to use XML file for bean and job definition.
Let’s prepare for it.
Preparation
This example is very simple.
No database, No file input.
Only One job and one tasklet(no reader, ….)
bean definition(XML)
Create job definition file under src/main/java
job.xml
<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/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd http://www.springframework.org/schema/batch http://www.springframework.org/schema/batch/spring-batch.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="jobLauncher" class="org.springframework.batch.core.launch.support.SimpleJobLauncher"> <property name="jobRepository" ref="jobRepository" /> </bean> <batch:job id="firstjob" job-repository="jobRepository"> <batch:step id="task1"> <batchlet class="com.atmarkplant.batchsample.task.FirstTasklet" /> </batch:step> </batch:job> </beans>
com.atmarkplant.batchsample.task.FirstTasklet is my codes, others are spring prepared class.
In this time, I don’t use any datasource, for example, database
Job definition is under batch:job
com.atmarkplant.batchsample.task.FirstTasklet
public class FirstTasklet implements Tasklet { @Override public RepeatStatus execute(StepContribution contribution, ChunkContext chunkContext) throws Exception { System.out.println("task 1"); return RepeatStatus.FINISHED; } }
Run(Debug) from eclipse
To run this project project, we need to change default run configuration.