Skip to content

Update reference documentation as Spring Batch's resourceless infrastructure means that it no longer always requires a DataSource #48233

@ah1508

Description

@ah1508

Spring Boot can create the tables used by Spring batch to store statistics about job and step execution if the spring.batch.jdbc.initialize-schema is set to always

See: https://docs.spring.io/spring-boot/how-to/data-initialization.html#howto.data-initialization.batch

With Spring Batch 6, the default behavior does not store anything, because a ResourcelessJobRepository is register in the context so schema initialization does not make sense.

@EnableJdbcJobRepository enables JDBC storage: a SimpleJobRepository is registered in the context and setting spring.batch.jdbc.initialize-schema to always should trigger tables creation:

@SpringBootApplication
@EnableBatchProcessing // otherwise @EnableJdbcJobRepository has no effect
@EnableJdbcJobRepository
public class EntryPoint {

    @Bean
    Job job(JobRepository jobRepository){
        return new JobBuilder("job", jobRepository)
                .start(new StepBuilder("step", jobRepository)
                        .tasklet((_, _)-> RepeatStatus.FINISHED)
                        .build())
                .build();
    }

    public static void main(String[] args) {
        var ctx = SpringApplication.run(EntryPoint.class, "spring.batch.jdbc.initialize-schema=always");
        System.out.println(ctx.getBean(JobRepository.class));
    }
}

But it does not: tables are not created.

If there is something more to do it should be written in the documentation somewhere. Search for spring.batch.jdbc.initialize-schema in the Spring batch documentation does not give any result related to schema creation (probably because it's Spring boot responsability).

Sample here with the code hereabove and a h2 database and spring-boot-starter-batch-jdbc

demo-issue.zip

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions