【问题标题】:How to access meta-data tables in on a different schema to a Spring Boot + Batch application?如何访问与 Spring Boot + Batch 应用程序不同的模式中的元数据表?
【发布时间】:2015-02-15 19:15:04
【问题描述】:

在我的 Spring Boot 应用程序中,我喜欢使用具有特定模式的 Spring Batch 元表。 documentation 建议使用表前缀。

我尝试将batch.table.prefix=abc.BATCH_ 添加到属性文件中。我也尝试覆盖配置:

@Configuration
@EnableBatchProcessing
public class BatchConfig {

    @Bean
    public JobRepository jobRepository(DataSource dataSource) throws Exception {
        final JobRepositoryFactoryBean factory = new JobRepositoryFactoryBean();
        factory.setDataSource(dataSource);
        factory.setTablePrefix("abc.BATCH_");
        factory.setTransactionManager(transactionManager(dataSource));
        factory.afterPropertiesSet();
        return factory.getObject();
    }

    @Bean
    public JobExplorer jobExplorer(DataSource dataSource) throws Exception {
        final JobExplorerFactoryBean factory = new JobExplorerFactoryBean();
        factory.setDataSource(dataSource);
        factory.setTablePrefix("abs.BATCH_");
        factory.afterPropertiesSet();
        return factory.getObject();
    }

    @Bean
    public PlatformTransactionManager transactionManager(DataSource dataSource) {
        return new DataSourceTransactionManager(dataSource);
    }

    ...
}

但我总是得到错误: 引起:org.h2.jdbc.JdbcSQLException:找不到表“BATCH_JOB_INSTANCE”; SQL 语句: 从 BATCH_JOB_INSTANCE 中选择 JOB_INSTANCE_ID、JOB_NAME,其中 JOB_NAME = ?和 JOB_KEY = ? [42102-182]

【问题讨论】:

    标签: spring spring-boot spring-batch


    【解决方案1】:

    我认为使用@EnableBatchProcessing 更改存储库/资源管理器的最佳方法是提供您自己的BatchConfigurer(只是一个bean 定义)。您可以轻松扩展现有实例之一。

    【讨论】:

      【解决方案2】:

      在我的情况下,我使用 mysql 作为数据库,我得到了这个错误。我是这样解决的:

      1.从以下 jar spring-batch-core jar 复制 mysql(eg.mongo db、hsqldb 等) 查询(创建和插入查询)。

      2.在您使用过的数据库(如mysql、mongo、hsqldb等)中粘贴插入和创建查询并执行它们,将创建所需的表并将表中的数据插入到相应的表中。

      3.运行你的批处理程序,它会找到“batch_job_instance”表和其他需要的表。

      【讨论】:

      • 这是手动的,但是如果我们可以手动的话有什么办法吗?
      猜你喜欢
      • 2015-09-08
      • 2020-04-20
      • 2020-11-01
      • 1970-01-01
      • 1970-01-01
      • 2015-11-03
      • 2011-10-16
      • 2021-11-19
      • 2016-11-14
      相关资源
      最近更新 更多