Spring批处理作业未创建表格。

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

Spring batch job not creating tables

问题

以下是您要翻译的内容:

我有一个使用注释的配置类

元数据表已创建,但没有表前缀。
Initialize-schema始终是CUSTOM_

@Configuration
@Slf4j
@EnableBatchProcessing
public class BatchConfiguration {

    @Autowired
    private JobParametersValidator jobParametersValidator;

    @Value("${spring.datasource.url}")
    private String postgresUrl;

    @Value("${spring.datasource.username}")
    private String postgresUserName;

    @Value("${spring.datasource.password}")
    private String postgresPassword;

    private String postgresSchema = "public";


    @Bean("dataSource")
    @Primary
    public DataSource dataSource() {
        HikariDataSource hikariDataSource = new HikariDataSource();
        hikariDataSource.setJdbcUrl(this.postgresUrl);
        hikariDataSource.setUsername(this.postgresUserName);
        hikariDataSource.setPassword(this.postgresPassword);
        hikariDataSource.setSchema(this.postgresSchema);
        return hikariDataSource;
    }

    @Bean
    public JpaTransactionManager transactionManager(){
        JpaTransactionManager transactionManager = new JpaTransactionManager();
        transactionManager.setDataSource(dataSource());
        return transactionManager;
    }

    @Bean
    public Job...

}

我的application.yml如下:

spring:
  application:
    name: ${APPLICATION_NAME}
  batch:
    jdbc:
      initialize-schema: ALWAYS
      table-prefix: CUSTOM_
    job:
      enabled: false

我缺少什么来初始化带有正确表前缀的架构

库:
spring-boot-starter-batch:3.0.5
它包括spring-batch-core:5.0.1

英文:

I have a configuration class annotated with

The metadata tables are getting created but without table prefix.
Initialize-schema is ALWAYS and table-prefix is CUSTOM_

@Configuration
@Slf4j
@EnableBatchProcessing
public class BatchConfiguration {

    @Autowired
    private JobParametersValidator jobParametersValidator;

    @Value("${spring.datasource.url}")
    private String postgresUrl;

    @Value("${spring.datasource.username}")
    private String postgresUserName;

    @Value("${spring.datasource.password}")
    private String postgresPassword;

    private String postgresSchema = "public";


    @Bean("dataSource")
    @Primary
    public DataSource dataSource() {
        HikariDataSource hikariDataSource = new HikariDataSource();
        hikariDataSource.setJdbcUrl(this.postgresUrl);
        hikariDataSource.setUsername(this.postgresUserName);
        hikariDataSource.setPassword(this.postgresPassword);
        hikariDataSource.setSchema(this.postgresSchema);
        return hikariDataSource;
    }

    @Bean
    public JpaTransactionManager transactionManager(){
        JpaTransactionManager transactionManager = new JpaTransactionManager();
        transactionManager.setDataSource(dataSource());
        return transactionManager;
    }
   
    @Bean
    public Job...


}

My application.yml looks like:

spring:
  application:
    name: ${APPLICATION_NAME}
  batch:
    jdbc:
      initialize-schema: ALWAYS
      table-prefix: CUSTOM_
    job:
      enabled: false

What am I missing to initialize the schema with correct table prefix

libraries:
spring-boot-starter-batch:3.0.5
It comprises of spring-batch-core:5.0.1

答案1

得分: 2

使用Spring Boot 3,当您添加@EnableBatchProcessing时,Spring Batch的自动配置(元数据表创建、启动时作业的启动等)将被禁用。因此,您已配置的spring.batch.*属性不会产生任何效果。

这在Spring Boot 3的迁移指南中有提到。

英文:

With Spring Boot 3, when you add @EnableBatchProcessing, the auto-configuration of Spring Batch (meta-data tables creation, launching of jobs at startup, etc) will back off. As a result, the spring.batch.* properties that you have configured do not have any effect.

This is mentioned in the migration guide of Spring Boot 3.

huangapple
  • 本文由 发表于 2023年5月25日 18:36:38
  • 转载请务必保留本文链接:https://go.coder-hub.com/76331356.html
匿名

发表评论

匿名网友

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

确定