Spring Boot provides facilities for the execution of batch jobs easily within an über-jar. Spring Boot’s support of this functionality allows for a developer to execute multiple batch jobs within that execution. Spring Cloud Task provides the ability to associate the execution of a job (a job execution) with a task’s execution so that one can be traced back to the other.
This functionality is accomplished by using the TaskBatchExecutionListener
. By default,
this listener is auto configured in any context that has both a Spring Batch Job configured
(via having a bean of type Job
defined in the context) and the spring-cloud-task-batch jar
is available within the classpath. The listener will be injected into all jobs.
To prevent the listener from being injected into any batch jobs within the current context, the autoconfiguration can be disabled via standard Spring Boot mechanisms.
To only have the listener injected into particular jobs within the context, the
batchTaskExecutionListenerBeanPostProcessor
may be overridden and a list of job bean ids
can be provided:
public TaskBatchExecutionListenerBeanPostProcessor batchTaskExecutionListenerBeanPostProcessor() { TaskBatchExecutionListenerBeanPostProcessor postProcessor = new TaskBatchExecutionListenerBeanPostProcessor(); postProcessor.setJobNames(Arrays.asList(new String[] {"job1", "job2"})); return postProcessor; }
![]() | Note |
---|---|
A sample batch application can be found in the samples module of the Spring Cloud Task Project here. |