Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Spring Batch: get list of defined jobs at runtime

Is it possible to get a list of defined jobs in Spring Batch at runtime without using db? Maybe it's possible to get this metadata from jobRepository bean or some similar object?

like image 652
Vladyslav Sheruda Avatar asked Sep 04 '15 14:09

Vladyslav Sheruda


People also ask

What is JobExplorer in Spring Batch?

public interface JobExplorer. Entry point for browsing executions of running or historical jobs and steps. Since the data may be re-hydrated from persistent storage, it may not contain volatile fields that would have been present when the execution was active.

What is JobOperator in Spring Batch?

public interface JobOperator. Low level interface for inspecting and controlling jobs with access only to primitive and collection types. Suitable for a command-line client (e.g. that launches a new process for each operation), or a remote launcher like a JMX console.

What is ExecutionContext in Spring Batch?

An ExecutionContext is a set of key-value pairs containing information that is scoped to either StepExecution or JobExecution . Spring Batch persists the ExecutionContext , which helps in cases where you want to restart a batch run (e.g., when a fatal error has occurred, etc.).


1 Answers

It is possible to retrieve the list of all job names using JobExplorer.getJobNames().

You first have to define the jobExplorer bean using JobExplorerFactoryBean:

<bean id="jobExplorer" class="org.springframework.batch.core.explore.support.JobExplorerFactoryBean">
    <property name="dataSource" ref="dataSource"/>
</bean>

and then you can inject this bean when you need it.

like image 189
Tunaki Avatar answered Sep 28 '22 05:09

Tunaki