不同模式中的 Spring 批处理表 [英] Spring batch tables in a different schema
问题描述
我想使用不同的模式来保存 Spring Batch 表.我可以在 JobRepositoryFactoryBean
中看到我的新数据源.但是这些表仍然是在我有业务表的另一个 shcema 中创建的.我读到一些我可以使用 dataSource.setValidationQuery
来改变架构的地方,但仍然不起作用.我可以解决这个问题.下面是 JobRepositoryFactoryBean
和 Datasource
属性.
I want to use a different schema to save Spring Batch tables. I can see that my new datasource in set in the JobRepositoryFactoryBean
. But still the tables are been created in the other shcema where I have business tables. I read soemwhere that I can use dataSource.setValidationQuery
to alter the schema, but still doesn't work. I can solve this. Below is the JobRepositoryFactoryBean
and Datasource
prop.
@Bean
@Qualifier("batchDataSource")
protected JobRepository createJobRepository() throws Exception {
JobRepositoryFactoryBean factory = createJobRepositoryFactoryBean();
factory.setDataSource(getDataSource());
if (getDbType() != null) {
factory.setDatabaseType(getDbType());
}
factory.setTransactionManager(getTransactionManager());
factory.setIsolationLevelForCreate(getIsolationLevel());
factory.setMaxVarCharLength(maxVarCharLength);
factory.setTablePrefix(getTablePrefix());
factory.setValidateTransactionState(validateTransactionState);
factory.afterPropertiesSet();
return factory.getObject();
}
spring.datasource.url=url
spring.datasource.username=username
spring.datasource.password=pwd
spring.datasource.driver-class-name:oracle.jdbc.driver.OracleDriver
spring.datasource.validation-query=ALTER SESSION SET
CURRENT_SCHEMA=schemaname
#batch setting
spring.batch.datasource.url=burl
spring.batch.datasource.username=busername
spring.batch.datasource.password=bpwd
spring.batch.datasource.driver-class-name:oracle.jdbc.driver.OracleDriver
spring.batch.datasource.validation-query=ALTER SESSION SET
CURRENT_SCHEMA=batchschema
org.apache.tomcat.jdbc.pool.DataSource dataSource = new org.apache.tomcat.jdbc.pool.DataSource();
dataSource.setName("batchDataSourceName");
dataSource.setDriverClassName(batchDataSourceProperties.getDriverClassName());
dataSource.setUrl(batchDataSourceProperties.getUrl());
dataSource.setUsername(batchDataSourceProperties.getUsername());
dataSource.setPassword(batchDataSourceProperties.getPassword());
// dataSource.setValidationQuery(batchDataSourceProperties.getValidationQuery());
推荐答案
application.properties 中的以下属性对我有用.这将在您的数据库中的 new_schema 下创建元模式表.
Below property in application.properties is working for me.This will create meta schema tables under new_schema in your DB.
spring.batch.tablePrefix=new_schema.BATCH_
以下是我使用的springBoot版本.
Below is the version of springBoot I am using.
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.3.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
这篇关于不同模式中的 Spring 批处理表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!