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());
@EnableBatchProcessing
? – ShantelBatchConfigurer
to identify whichDataSource
to use for the batch schema? – Shantel