Skip to content

Spring Boot batch job does not shut down automatically after completion when using JPA #3725

@martinmogusu

Description

@martinmogusu

Bug description
I notice that a spring boot batch application does not shut down automatically after completing a job when using Spring data JPA. The job completes successfully but the spring boot application remains running and has to be stopped manually (e.g. by pressing Ctrl + C).

Environment
Spring boot version: 2.3.0.RELEASE
Java version: 1.8
OS: Windows

Steps to reproduce

  1. Create a new spring boot project from https://start.spring.io/
  2. Add the following dependencies:
  • spring-boot-starter-batch
  • spring-boot-starter-data-jpa
  • h2
  1. Create a tasklet step
  2. Configure a spring batch job referencing the tasklet step

Expected behavior
The job should execute successfully, and shut down automatically.

Minimal Complete Reproducible example

Dependencies in pom.xml

<dependency>
	<groupId>org.springframework.boot</groupId>
	<artifactId>spring-boot-starter-batch</artifactId>
</dependency>
<dependency>
	<groupId>org.springframework.boot</groupId>
	<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
	<groupId>com.h2database</groupId>
	<artifactId>h2</artifactId>
	<scope>runtime</scope>
</dependency>

Batch configuration class

@Configuration
public class BatchConfiguration {

    @Bean
    public Job sampleJob(JobBuilderFactory jobBuilderFactory, Step step1) {
        return jobBuilderFactory.get("sampleJob").incrementer(new RunIdIncrementer()).flow(step1).end().build();
    }

    @Bean
    public Step step1(StepBuilderFactory stepBuilderFactory, StepTasklet tasklet) {
        return stepBuilderFactory.get("step1").tasklet(tasklet).build();
    }

}

Tasklet step class

public class StepTasklet implements Tasklet {

    @Override
    public RepeatStatus execute(StepContribution contribution, ChunkContext chunkContext) throws Exception {
        System.out.println("Executing tasklet step...");
        return RepeatStatus.FINISHED;
    }
    
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    for: external-projectIssues that should be opened against other Spring projectsstatus: invalidLegacy label from JIRA. Superseded by "status: declined"type: bug

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions