James Schermann James Schermann - 9 months ago 67
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

bean or some similar object?

Answer Source

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"/>

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