James Schermann James Schermann - 1 month ago 18
Java Question

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?

Answer

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.