Search code examples
javaspringspring-batchspring-cloud-dataflow

How to retrieve the taskExecutionId during a job in Spring Batch?


(For logging purposes,) I need to retrieve the (task) execution id inside a job execution in Spring Cloud Data Flow. In particular, I have access to several "job" objects (JobLauncher, JobExplorer, JobRepository, JobExecution...), which don't seem to keep a correlation to the task. Moreover, something like @Value("{$spring.cloud.task.executionid:}") doesn't seem to work.


Solution

  • You can use a Task Execution Listener.

    You can let any bean implement TaskExecutionListener (or use the annotations @BeforeTask, @AfterTask, @FailedTask) and take the id from the TaskExecution that is passed as argument to its methods.