Skip to content

spring.batch.jdbc.initialize-schema=always not working anymore #4252

@giuliana-bezerra

Description

@giuliana-bezerra

Bug description
When using spring.batch.jdbc.initialize-schema=always in my application properties, the spring batch schema is not created

Environment
Spring Batch version: 5.0
Java version: OpenJDK Runtime Environment Temurin-17.0.4+8
Database: H2
SO: MacOS Ventura 13.0

Steps to reproduce
Just run a job with the property spring.batch.jdbc.initialize-schema=always with h2 database.

Expected behavior
When using the prop spring.batch.jdbc.initialize-schema=always in the previous version, the framework initialized the metadata schema before executing the job. Now, this property doesn't work, and I had to init the schema programmatically, which is not very practical:

@Primary
@Bean
public DataSource dataSource() {
  return new EmbeddedDatabaseBuilder().setType(EmbeddedDatabaseType.H2)
      .addScript("/org/springframework/batch/core/schema-h2.sql")
      .generateUniqueName(true).build();
}

Minimal Complete Reproducible example
pom.xml

<parent>
  <groupId>org.springframework.boot</groupId>
  <artifactId>spring-boot-starter-parent</artifactId>
  <version>3.0.0</version>
  <relativePath /> <!-- lookup parent from repository -->
</parent>
<properties>
  <java.version>17</java.version>
</properties>
<dependencies>
  <dependency>
	  <groupId>org.springframework.boot</groupId>
	  <artifactId>spring-boot-starter-batch</artifactId>
  </dependency>
  <dependency>
	  <groupId>org.springframework.boot</groupId>
	  <artifactId>spring-boot-starter-test</artifactId>
	  <scope>test</scope>
  </dependency>
  <dependency>
	  <groupId>org.springframework.batch</groupId>
	  <artifactId>spring-batch-test</artifactId>
	  <scope>test</scope>
  </dependency>
  
  <dependency>
	  <groupId>com.h2database</groupId>
	  <artifactId>h2</artifactId>
	  <scope>runtime</scope>
  </dependency>
</dependencies>

BatchConfig:

package br.com.giulianabezerra.springbatchv5;

import org.springframework.batch.core.Job;
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.job.builder.JobBuilder;
import org.springframework.batch.core.repository.JobRepository;
import org.springframework.batch.core.scope.context.ChunkContext;
import org.springframework.batch.core.step.builder.StepBuilder;
import org.springframework.batch.repeat.RepeatStatus;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.transaction.PlatformTransactionManager;

@EnableBatchProcessing
@Configuration
public class BatchConfig {

  @Bean
  public Job job(JobRepository jobRepository, PlatformTransactionManager transactionManager,
      Step step) {
    return new JobBuilder("job", jobRepository)
        .start(step)
        .build();
  }

  @Bean
  public Step step(JobRepository jobRepository, PlatformTransactionManager transactionManager) {
    return new StepBuilder("step", jobRepository)
        .tasklet((StepContribution contribution, ChunkContext chunkContext) -> {
          System.out.println("Hello, world!");
          return RepeatStatus.FINISHED;
        }, transactionManager)
        .build();
  }
}

Application:

package br.com.giulianabezerra.springbatchv5;

import org.springframework.batch.core.Job;
import org.springframework.batch.core.JobParameters;
import org.springframework.batch.core.launch.JobLauncher;
import org.springframework.boot.ApplicationRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;

@SpringBootApplication
public class SpringBatchV5Application {
	public static void main(String[] args) {
		SpringApplication.run(SpringBatchV5Application.class, args);
	}

	@Bean
	ApplicationRunner applicationRunner(JobLauncher jobLauncher, Job job) {
		return args -> jobLauncher.run(job, new JobParameters());
	}
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    for: external-projectIssues that should be opened against other Spring projectsstatus: declinedFeatures that we don't intend to implement or Bug reports that are invalid or missing enough details

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions