Migrating Spring Boot (3.0.5) with Spring Batch(5.0): Spring Batch specific "Auto Table creation" is not working

huangapple go评论50阅读模式
英文:

Migrating Spring Boot (3.0.5) with Spring Batch(5.0): Spring Batch specific "Auto Table creation" is not working

问题

老版本:
Java: 11
Spring Boot: 2.5.2

迁移后(新版本):
Java: 17
Spring Boot: 3.0.5
Spring Batch: 5.0

问题:
与Spring Batch相关的元数据(自动创建表)不再起作用(在升级前,在bootstrap.yml中定义了“spring.jdbc.initialize-schema: always”,之前运行良好)。
spring.datasource.url,spring.datasource.username,spring.datasource.password和spring.datasource.schema都按原样定义(升级前运行良好)。

只是为了尝试:已为Spring Boot定义了以下内容以读取主数据源(这是Spring Batch特定的,不是应用程序特定的),但没有成功。

@Configuration
public class DBConfig {
    @Primary
    @Bean(name = "dataSource")
    public DataSource dataSource() {
        DataSource dataSource = DataSourceBuilder.create().username("XXX")
                  .password("XXX$").url("jdbc:oracle:thin:@host:port/XXX").build();
        return dataSource;
    }
}
英文:

Old versions:
Java: 11
Spring Boot : 2.5.2

After Migration : (new versions)
Java:17
Spring Boot: 3.0.5
Spring Batch 5.0

Problem:

Spring batch related meta data (Auto table creation) is not working any more. (having “spring.jdbc.initialize-schema: always” defined in bootstrap.yml,and was working fine before upgrade)
spring.datasource.url, spring.datasource.username, spring.datasource.password and spring.datasource.schema are all defined as it is (working before).

Just to try out: have defined below for Spring Boot to read the primary data source (which is spring Batch specific and not application specific) but no luck.

 @Configuration`
    public class DBConfig {
    @Primary
    @Bean(name = "dataSource")
    public DataSource dataSource() {
        DataSource dataSource = DataSourceBuilder.create().username("XXX")
                      .password("XXX$").url("jdbc:oracle:thin:@host:port/XXX").build();
        return dataSource;
    }
   }

答案1

得分: 1

I guess you are using @EnableBatchProcessing. If this is the case, that is the reason why tables are not created, see https://github.com/spring-projects/spring-boot/wiki/Spring-Boot-3.0-Migration-Guide#enablebatchprocessing-is-now-discouraged.

如果您正在使用@EnableBatchProcessing,那么这就是表格未被创建的原因,请参阅 https://github.com/spring-projects/spring-boot/wiki/Spring-Boot-3.0-Migration-Guide#enablebatchprocessing-is-now-discouraged.

If you want to use @EnableBatchProcessing, then you need to initialize the database yourself, see example in https://stackoverflow.com/questions/75619930/spring-batch-5-and-spring-boot-3-meta-data-tables-not-created-when-using-program

如果您想使用@EnableBatchProcessing,那么您需要自行初始化数据库,请参考 https://stackoverflow.com/questions/75619930/spring-batch-5-and-spring-boot-3-meta-data-tables-not-created-when-using-program

英文:

I guess you are using @EnableBatchProcessing. If this is the case, that is the reason why tables are not created, see https://github.com/spring-projects/spring-boot/wiki/Spring-Boot-3.0-Migration-Guide#enablebatchprocessing-is-now-discouraged.

If you want to use @EnableBatchProcessing, then you need to initialize the database yourself, see example in https://stackoverflow.com/questions/75619930/spring-batch-5-and-spring-boot-3-meta-data-tables-not-created-when-using-program

huangapple
  • 本文由 发表于 2023年4月17日 14:54:53
  • 转载请务必保留本文链接:https://go.coder-hub.com/76032394.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定