Spring batch had it\'s own database schema.
My application has it\'s own database schema.
I want to keep these separated into different databases so the spring-bat
Well this is how I did it.
In application.properties
### Database Details
datasource.app.driverClassName=oracle.jdbc.driver.OracleDriver
datasource.app.url=jdbc:oracle:thin:@//localhost:1521/xe
datasource.app.username=YOUR_APP_DB_USERNAME
datasource.app.password=YOUR_PASSWORD
datasource.batch.driverClassName=oracle.jdbc.driver.OracleDriver
datasource.batch.url=jdbc:oracle:thin:@//localhost:1521/xe
datasource.batch.username=YOUR_BATCH_DB_USERNAME
datasource.batch.password=YOUR_PASSWORD
And in your @Configuration
class add the following beans
@Primary
@Bean
@ConfigurationProperties(prefix = "datasource.app")
public DataSource appDataSource() {
return DataSourceBuilder.create().build();
}
@Bean
@ConfigurationProperties(prefix = "datasource.batch")
public DataSource batchDataSource() {
return DataSourceBuilder.create().build();
}
@Bean
public JobLauncher jobLauncher() throws Exception {
SimpleJobLauncher jobLauncher = new SimpleJobLauncher();
jobLauncher.setJobRepository(jobRepository());
return jobLauncher;
}
@Bean
public JobRepository jobRepository() throws Exception {
DataSourceTransactionManager batchTransactionManager = new DataSourceTransactionManager();
batchTransactionManager.setDataSource(batchDataSource());
JobRepositoryFactoryBean jobRepositoryFactoryBean = new JobRepositoryFactoryBean();
jobRepositoryFactoryBean.setTransactionManager(batchTransactionManager);
jobRepositoryFactoryBean.setDatabaseType("ORACLE");
jobRepositoryFactoryBean.setIsolationLevelForCreate("ISOLATION_DEFAULT");
jobRepositoryFactoryBean.setDataSource(batchDataSource());
jobRepositoryFactoryBean.afterPropertiesSet();
return jobRepositoryFactoryBean.getObject();
}