I am using @BatchDataSource with reference to https://github.com/spring-projects/spring-boot/issues/9114 and https://github.com/spring-projects/spring-boot/issues/28932.

However, if @BatchDataSource is not accessible, the application does not run even if job.enabled is false.

Can skip errors with this PR.

This is my setup.

spring:
  datasource:
    url: jdbc:mysql://{{accessible database}}/db
  datasource-batch: #custom
    url: jdbc:mysql://{{unreachable database}}/db
  jpa:
    database: mysql
  batch:
    jdbc:
      platform: mysql
    job:
      enabled: false

This is error content.

Caused by: java.lang.IllegalStateException: Unable to initialize Spring Batch
    at org.springframework.boot.autoconfigure.batch.BasicBatchConfigurer.initialize(BasicBatchConfigurer.java:106)
    at org.springframework.boot.autoconfigure.batch.BasicBatchConfigurer.afterPropertiesSet(BasicBatchConfigurer.java:95)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1863)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1800)
    ... 33 common frames omitted
Caused by: org.springframework.jdbc.support.MetaDataAccessException: Could not get Connection for extracting meta-data; nested exception is org.springframework.jdbc.CannotGetJdbcConnectionException: Failed to obtain JDBC Connection; nested exception is java.sql.SQLNonTransientConnectionException: Could not create connection to database server. Attempted reconnect 3 times. Giving up.
    at org.springframework.jdbc.support.JdbcUtils.extractDatabaseMetaData(JdbcUtils.java:363)
    at org.springframework.jdbc.support.JdbcUtils.extractDatabaseMetaData(JdbcUtils.java:395)
    at org.springframework.batch.support.DatabaseType.fromMetaData(DatabaseType.java:102)
    at org.springframework.batch.core.repository.support.JobRepositoryFactoryBean.afterPropertiesSet(JobRepositoryFactoryBean.java:183)
    at org.springframework.boot.autoconfigure.batch.BasicBatchConfigurer.createJobRepository(BasicBatchConfigurer.java:133)
    at org.springframework.boot.autoconfigure.batch.BasicBatchConfigurer.initialize(BasicBatchConfigurer.java:101)
    ... 36 common frames omitted

Comment From: pivotal-cla

@o1i0 Please sign the Contributor License Agreement!

Click here to manually synchronize the status of this Pull Request.

See the FAQ for frequently asked questions.

Comment From: pivotal-cla

@o1i0 Thank you for signing the Contributor License Agreement!

Comment From: wilkinsona

Thanks for the suggestion.

The platform property is used to determine the schema script that's used to prepare that database. Unfortunately, I don't think we can expand that and also use it for the database type as there isn't a perfect mapping between the platform name in the schema files and the values in DatabaseType. For example, the schema scripts use postgresql but DatabaseType uses postgres. DatabaseType also has four entries for different flavours of DB2 but the schema scripts only have db2.

Thanks again for the suggestion and sorry that we can't use it. If you'd like us to look an alternative way to configure the DatabaseType, please open an issue and we'll take a look.