Database 如何禁用Spring批处理元数据表调用
我正在创建一个示例Spring批处理应用程序。Spring批处理版本是2.2.7,java版本是1.7。 在应用程序属性文件中,我放置spring.batch.initializeschema=never。我不需要将作业元数据存储在内存数据库或我的数据库中的任何位置。但是当我运行应用程序时,我会遇到如下错误,如何避免这种情况。请帮忙Database 如何禁用Spring批处理元数据表调用,database,spring-batch,java-7,Database,Spring Batch,Java 7,我正在创建一个示例Spring批处理应用程序。Spring批处理版本是2.2.7,java版本是1.7。 在应用程序属性文件中,我放置spring.batch.initializeschema=never。我不需要将作业元数据存储在内存数据库或我的数据库中的任何位置。但是当我运行应用程序时,我会遇到如下错误,如何避免这种情况。请帮忙 org.springframework.jdbc.BadSqlGrammarException: PreparedStatementCallback; bad SQ
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。但它仍在寻找数据源(错误:数据源不能为null)
当您使用
@EnableBatchProcessing
时,默认情况下,Spring Batch将使用您在应用程序上下文中定义的数据源作为其元数据。如果要使用基于映射的作业存储库,则需要实现BatchConfigurer
并覆盖getJobRepositoy
您可以在此处的文档中找到更多详细信息:我为您的问题添加了答案。请接受它,如果它有帮助:可能是我没有按照你的答案正确。添加了更多的代码以尝试实现您的建议。您是否已从
SpringConfig
类中删除了getJobRepository
、getTransactionManager
和getJobLauncher
中的方法?请用代码的最新状态更新问题,因为现在我看到这些方法在SpringConfig
类和BatchJobConfig
类中重复。您也可以使SpringConfig
extendDefaultBatchConfigurer
。通过尝试实现BatchConfigurer添加了新的代码段,但我仍然得到DS不能为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;
}