I am new to Spring Boot. I'm trying to write an application that takes advantage of Spring Batch to write data from one database to another. I'm reading from Mongo and writing to SQL Server. I am hosting my JobRepository in-memory and have coded it to use HSQLDB.
I am having some issues pointing Spring.Batch to the proper Data Source so I'm focusing on ensuring that I'm writing my jobs to the HSQLDB now. To do that, I've essentially commented out the SQL DB for now.
I have the following BatchConfiguration class:
@Configuration
@EnableBatchProcessing
public class BatchConfigurer extends DefaultBatchConfigurer {
@Autowired
@Qualifier("batchDataSource")
public DataSource batchDataSource;
@Bean
public JdbcTemplate jdbcTemplate(DataSource dataSource){
return new JdbcTemplate(dataSource);
}
@Bean
public JdbcTransactionManager batchTransactionManager() {
final JdbcTransactionManager transactionManager = new JdbcTransactionManager();
transactionManager.setDataSource(batchDataSource);
return transactionManager;
}
@Bean
public JobRepository jobRepositoryBean() throws Exception {
JobRepositoryFactoryBean fb = new JobRepositoryFactoryBean();
fb.setDatabaseType("HSQL");
fb.setDataSource(batchDataSource);
fb.setTransactionManager(batchTransactionManager());
return fb.getObject();
}
@Override
@Bean
protected JobLauncher createJobLauncher() throws Exception {
SimpleJobLauncher jobLauncher = new SimpleJobLauncher();
jobLauncher.setJobRepository(this.jobRepositoryBean());
jobLauncher.setTaskExecutor(new SimpleAsyncTaskExecutor());
jobLauncher.afterPropertiesSet();
return jobLauncher;
}
}
When I load this class I'm seeing the following output in the log:
2021-06-24 17:18:42.412 WARN 31940 --- [ main] o.s.b.c.c.a.DefaultBatchConfigurer : No transaction manager was provided, using a DataSourceTransactionManager
2021-06-24 17:18:42.419 INFO 31940 --- [ main] o.s.b.c.r.s.JobRepositoryFactoryBean : No database type set, using meta data indicating: HSQL
2021-06-24 17:18:43.154 WARN 31940 --- [ main] JpaBaseConfiguration$JpaWebConfiguration : spring.jpa.open-in-view is enabled by default. Therefore, database queries may be performed during view rendering. Explicitly configure spring.jpa.open-in-view to disable this warning
I'm trying to understand why the database type is inferred. It looks like I'm setting it already. Furthermore, when I uncomment the other Data Source the inferred type is SQLSERVER, which is wrong. Am I incorrectly initializing and setting the configuration for this data type?
I figured I'd try to get this working well before tackling the multiple data source situation again.