I want to use a different datasource for spring batch and created the below configuration class and autowired my required datasource to this as per the documentation.
I am using spring boot(2.2.6) and spring batch version 4.2.1.RELEASE
@Configuration
public class CustomBatchConfigurer extends DefaultBatchConfigurer {
@Autowired
@Qualifier("oracleDataSource")
private DataSource dataSource;
@Autowired
private PlatformTransactionManager transactionManager;
@Override
protected JobRepository createJobRepository() throws Exception {
JobRepositoryFactoryBean factory = new JobRepositoryFactoryBean();
factory.setDataSource(dataSource);
factory.setTransactionManager(transactionManager);
factory.setIsolationLevelForCreate("ISOLATION_READ_COMMITTED");
factory.setTablePrefix("MYDB.BATCH_");
factory.setMaxVarCharLength(1000);
factory.afterPropertiesSet();
return factory.getObject();
}
}
But when I start my application with this , it never applies the setTablePrefix and it always fails with table not found error.
I need to use above as I have two different datasource and I need spring batch to use my oracleDataSource bean.
If I disable non oracleDataSource bean and move the proprieties to application.properties, everything works fine.
Please guide on how this can be fixed. I saw a similar issue here where the user was complaining about same table not found issue after extending DefaultBatchConfigurer class Spring batch tables in a different schema