Creating a job
We'll create a job that will simply execute some Java code. It will be a job with only one step. The step will be a Tasklet
object (a single task, as opposed to a read-process-write step, which we'll cover later). We will execute this job in two different ways in the next two recipes.
How to do it…
Create a Tasklet
class, which you will use to define a step and the job:
Create the
Task1
class implementingTasklet
:public class Task1 implements Tasklet { }
In the
Task1
class, add anexecute()
method with the code to be executed for the job:public RepeatStatus execute(StepContribution contribution, ChunkContext chunkContext) throws Exception { System.out.println("Starting job.."); // ... your code System.out.println("Job done.."); return RepeatStatus.FINISHED; }
In the configuration class, add an autowired
JobBuilderFactory
attribute and an autowiredStepBuilderFactory
attribute:@Autowired private JobBuilderFactory jobs; @Autowired private StepBuilderFactory...