Search code examples
spring-bootspring-batchh2spring-cloud-task

Migrating H2 configuration in Spring Batch for Spring Boot 2.7


I need to migrate a project from Spring Boot 2.5.3 to 2.7.3 (and, if significant, also Spring Cloud from 2020.0.3 to 2021.0.3 and Spring Batch from 4.3.3 to 4.3.6). The main issue is that when using Spring Batch and H2, I get this error

org.springframework.context.ApplicationContextException: Failed to start bean 'taskLifecycleListener'; 
nested exception is org.springframework.dao.DataAccessResourceFailureException: 
Could not obtain sequence value; nested exception is org.h2.jdbc.JdbcSQLSyntaxErrorException: 
Sequence "TASK_SEQ" not found; SQL statement:
select next value for TASK_SEQ [90036-214]

As there was a H2 version upgrade the problem probably lies with my configuration, that was the following:

spring:
  batch.initialize-schema: embedded
  datasource:
    driverClassName: org.h2.Driver
    password: password
    url: jdbc:h2:mem:testdb
    username: sa
    platform: h2
    initialization-mode: embedded

I also tried to use the legacy compatibility mode in the jdbc string jdbc:h2:mem:testdb;MODE=LEGACY, without success.


Solution

  • While my issue was trivial (I forgot to copy cloud.task.initialize-enabled: true in the new config), I found another significant problem: spring.datasource.platform was deprecated and now is spring.sql.init.platform.