如何禁用 Spring 批处理元数据 Table 调用

How to Disable Spring Batch Meta Data Table Calls

我正在创建示例 Spring 批处理应用程序。 Spring批量版本是2.2.7java版本是1.7。 在应用程序 属性 文件中,我放置了 spring.batch.initialize-schema=never。我不需要将工作元数据存储在内存数据库或我的数据库中的任何地方。但是当我 运行 应用程序出现如下错误时,我该如何避免这种情况。请帮忙。

org.springframework.jdbc.BadSqlGrammarException: PreparedStatementCallback; bad SQL grammar [SELECT 
JOB_INSTANCE_ID, JOB_NAME from BATCH_JOB_INSTANCE where JOB_NAME = ? and JOB_KEY = ?]; nested 
exception is java.sql.SQLSyntaxErrorException: ORA-00942: table or view does not exist


@Configuration
@EnableBatchProcessing
public class SpringConfig {

@Bean
public DataSource dataSource() {
    final DriverManagerDataSource dataSource = new DriverManagerDataSource();
    dataSource.setDriverClassName("oracle.jdbc.driver.OracleDriver");
    dataSource.setUrl(url);
    dataSource.setUsername("root");
    dataSource.setPassword("root");
    return dataSource;
}
private JobRepository getJobRepository() throws Exception {
    JobRepositoryFactoryBean factory = new JobRepositoryFactoryBean();
    factory.setDataSource(dataSource());
    factory.setTransactionManager(getTransactionManager());
    factory.afterPropertiesSet();
    return (JobRepository) factory.getObject();
}

private PlatformTransactionManager getTransactionManager() {
    return new ResourcelessTransactionManager();
}

public JobLauncher getJobLauncher() throws Exception {
    SimpleJobLauncher jobLauncher = new SimpleJobLauncher();
    jobLauncher.setJobRepository(getJobRepository());
    jobLauncher.afterPropertiesSet();
    return jobLauncher;
}

}

// 尝试在我的配置中实现 BatchConfigurer class.But 仍然在寻找数据源(错误:DataSource 不能为 null)

public class BatchJobConfig  implements BatchConfigurer{ 

@Override
public JobRepository getJobRepository() throws Exception {
    JobRepositoryFactoryBean factory = new JobRepositoryFactoryBean();
    factory.setTransactionManager(getTransactionManager());
    factory.afterPropertiesSet();
    return (JobRepository) factory.getObject();
}

@Override
public PlatformTransactionManager getTransactionManager()  {
    return new ResourcelessTransactionManager();

}

@Override
public JobLauncher getJobLauncher() throws Exception {
    SimpleJobLauncher jobLauncher = new SimpleJobLauncher();
    jobLauncher.setJobRepository(getJobRepository());
    jobLauncher.afterPropertiesSet();
    return jobLauncher;
}

当您使用 @EnableBatchProcessing 时,默认情况下 Spring Batch 将使用您在应用程序上下文中为其元数据定义的数据源。如果要使用基于地图的作业存储库,则需要实施 BatchConfigurer 并覆盖 getJobRepositoy.

您可以在此处的文档中找到更多详细信息:https://docs.spring.io/spring-batch/docs/4.2.x/reference/html/job.html#javaConfig