我在应用程序属性中添加表前缀时遇到问题,Spring-Batch无法获取该属性,并设置了默认前缀BATCH _。
spring.batch.table-prefix=SOMETHING.BATCH_
春季版
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.4.RELEASE</version>
</parent>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<version>2.0.4.RELEASE</version>
<exclusions>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-logging</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-batch</artifactId>
<version>2.1.2.RELEASE</version>
</dependency>
org.springframework.jdbc.BadSqlGrammarException: PreparedStatementCallback;错误的SQL语法[SELECT JOB_INSTANCE_ID, 来自BATCH_JOB_INSTANCE的JOB_NAME,其中JOB_NAME =吗?和JOB_KEY =?]; 嵌套的异常是java.sql.SQLSyntaxErrorException:ORA-00942:表 或视图不存在
答案 0 :(得分:0)
我解决了这个问题,并且工作正常。
我注入了一个用JobRepositoryFactoryBean创建的新JobRepository。 在JobRepositoryFactoryBean中,我已经配置了数据源和前缀,并且在作业启动时,JdbcJobInstanceDao具有前缀。
我分享解决方案:
private PlatformTransactionManager transactionManager(){
return new ResourcelessTransactionManager();
}
private JobRepository createJobRepository() throws Exception {
JobRepositoryFactoryBean factory = new JobRepositoryFactoryBean();
factory.setDataSource(dataSourceAudit);
factory.setTransactionManager(transactionManager());
factory.setIsolationLevelForCreate("ISOLATION_READ_COMMITTED");
factory.setTablePrefix("SOMETHING.BATCH_");
factory.setDatabaseType("ORACLE");
factory.setMaxVarCharLength(1000);
return factory.getObject();
}
@Bean
public JobLauncher jobLauncherBc() throws Exception{
SimpleJobLauncher jobLauncher = new SimpleJobLauncher();
jobLauncher.setTaskExecutor(new SimpleAsyncTaskExecutor());
jobLauncher.setJobRepository(createJobRepository());
return jobLauncher;
}