Title: spring batch admin ui not showing jobs that are be configured
Tags: spring-boot;spring-batch;spring-batch-admin
Question: I have integrated spring boot with spring-batch-admin successfully. I used the sample guide from spring-batch for setting up jobs. I added couple of more tasklets to the jobs. my UI shows only one job. I expect to see three of them. I also the expect the three jobs to have start/stop functionalities and take job parameters from UI.
I have pushed entire code here.. please feel free to issue pull requests if you have solutions or improvements.
Here is my job.xml located in src/main/resources/batch/jobs/
<?xml version="1.0" encoding="UTF-8"?&gt;
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:batch="http://www.springframework.org/schema/batch"
xsi:schemaLocation="http://www.springframework.org/schema/batch http://www.springframework.org/schema/batch/spring-batch.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.1.xsd"&gt;
<!-- This is the XML way to define jobs but it will be very handy if you already have jobs like this --&gt;
<batch:job id="FirstJob" restartable="true"&gt;
<batch:step id="firstStep"&gt;
<batch:tasklet ref="firstTasklet" start-limit="1" /&gt;
</batch:step&gt;
</batch:job&gt;
<bean id="firstTasklet" class="hello.FirstTasklet"&gt;
<property name="property" value="${custom-property}" /&gt;
</bean&gt;
</beans&gt;
Here is my BatchConfiguration
package hello;
import javax.sql.DataSource;
import org.springframework.batch.core.Job;
import org.springframework.batch.core.JobExecutionListener;
import org.springframework.batch.core.Step;
import org.springframework.batch.core.StepContribution;
import org.springframework.batch.core.configuration.annotation.EnableBatchProcessing;
import org.springframework.batch.core.configuration.annotation.JobBuilderFactory;
import org.springframework.batch.core.configuration.annotation.StepBuilderFactory;
import org.springframework.batch.core.configuration.annotation.StepScope;
import org.springframework.batch.core.launch.support.RunIdIncrementer;
import org.springframework.batch.core.scope.context.ChunkContext;
import org.springframework.batch.core.step.tasklet.Tasklet;
import org.springframework.batch.item.database.BeanPropertyItemSqlParameterSourceProvider;
import org.springframework.batch.item.database.JdbcBatchItemWriter;
import org.springframework.batch.item.file.FlatFileItemReader;
import org.springframework.batch.item.file.mapping.BeanWrapperFieldSetMapper;
import org.springframework.batch.item.file.mapping.DefaultLineMapper;
import org.springframework.batch.item.file.transform.DelimitedLineTokenizer;
import org.springframework.batch.repeat.RepeatStatus;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.io.ClassPathResource;
import org.springframework.jdbc.core.JdbcTemplate;
@Configuration
//@EnableBatchProcessing
public class BatchConfiguration {
@Autowired
public JobBuilderFactory jobBuilderFactory;
@Autowired
public StepBuilderFactory stepBuilderFactory;
@Autowired
public DataSource dataSource;
//    @Value("#{jobParameters['file']:sample-data.csv}")
//    String filename;
// tag75b5:f2c1:f5d7:b954:8dc3:cee9:baf:a8c0readerwriterprocessor[]
@Bean
//@StepScope
public FlatFileItemReader<Person&gt; reader() {
FlatFileItemReader<Person&gt; reader = new FlatFileItemReader<Person&gt;();
reader.setResource(new ClassPathResource("sample-data.csv"));
reader.setLineMapper(new DefaultLineMapper<Person&gt;() {{
setLineTokenizer(new DelimitedLineTokenizer() {{
setNames(new String[] { "firstName", "lastName" });
}});
setFieldSetMapper(new BeanWrapperFieldSetMapper<Person&gt;() {{
setTargetType(Person.class);
}});
}});
return reader;
@Bean
public PersonItemProcessor processor() {
return new PersonItemProcessor();
@Bean
public JdbcBatchItemWriter<Person&gt; writer() {
JdbcBatchItemWriter<Person&gt; writer = new JdbcBatchItemWriter<Person&gt;();
writer.setItemSqlParameterSourceProvider(new BeanPropertyItemSqlParameterSourceProvider<Person&gt;());
writer.setSql("INSERT INTO people (first_name, last_name) VALUES (:firstName, :lastName)");
writer.setDataSource(dataSource);
return writer;
// en75b5:f2c1:f5d7:b954:8dc3:cee9:baf:a8c0readerwriterprocessor[]
// tag75b5:f2c1:f5d7:b954:8dc3:cee9:baf:a8c0jobstep[]
@Bean
public Job importUserJob(JobCompletionNotificationListener listener) {
return jobBuilderFactory.get("importUserJob")
.incrementer(new RunIdIncrementer())
.listener(listener)
.flow(step1())
.end()
.build();
@Bean
public Step step1() {
return stepBuilderFactory.get("step1")
.<Person, Person&gt; chunk(10)
.reader(reader())
.processor(processor())
.writer(writer())
.build();
// en75b5:f2c1:f5d7:b954:8dc3:cee9:baf:a8c0jobstep[]
@Bean
@StepScope
public FailableTasklet tasklet(@Value("#{jobParameters[fail]}") Boolean failable) {
if(failable != null) {
return new FailableTasklet(failable);
}
else {
return new FailableTasklet(false);
}
public static class FailableTasklet implements Tasklet {
private final boolean fail;
public FailableTasklet(boolean fail) {
this.fail = fail;
}
@Override
public RepeatStatus execute(StepContribution contribution, ChunkContext chunkContext) throws Exception {
System.out.println("Tasklet was executed");
if(fail) {
throw new RuntimeException("This exception was expected");
}
else {
return RepeatStatus.FINISHED;
}
}
screenshot of UI


Here is another answer: Spring Batch Admin UI displays only the Jobs. You wouldn't see steps/tasklets in the UI as they cannot be run individually. But after you run your job, you could see the stats of each step that was performed in that job. Hope this helps.

{'source': 'StackExchangeDataset', 'subset': 'stackoverflow.com', 'metadata': {'AnswerCount': 1, 'CommentCount': 0, 'ContentLicense': 'CC BY-SA 3.0', 'CreationDate': '2017:00:01/18/17', 'FavoriteCount': 1.0, 'PostTypeId': 1, 'Tags': '<spring-boot><spring-batch><spring-batch-admin>', 'Title': 'spring batch admin ui not showing jobs that are be configured', 'ViewCount': 660, 'id': 41731264, 'user_AboutMe': '', 'user_AccountId': 2258168.0, 'user_DisplayName': 'brain storm', 'user_Reputation': 28884.0, 'user_Views': 2227.0, 'user_id': 1988876.0}}