1

I am running a Spring Batch job and have two DataSource's configured like such:

@Bean
@Primary
@ConfigurationProperties(prefix="spring.datasource")
public DataSource mainDataSource() {
    return DataSourceBuilder.create().build();
}

@Bean("SpringBatchDataSource")
@ConfigurationProperties(prefix="spring.batch.datasource")
public DataSource batchDataSource() {
    return DataSourceBuilder.create().build();
}

As you can see of the two DataSources I have one is just for the Spring batch metadata.

This issue I'm having is Spring batch wants to use the @Primary DataSource. How can I configure it to use the batchDataSource?

DavidR
  • 6,622
  • 13
  • 56
  • 70
  • You can add `@primary` annotation to the `batchDataSource` method or try changing `batchDataSource` to simply `dataSource` – Amit Phaltankar Jun 01 '17 at 03:46
  • Possible duplicate of [Use of multiple DataSources in Spring Batch](https://stackoverflow.com/questions/25540502/use-of-multiple-datasources-in-spring-batch) – Michael Minella Jun 01 '17 at 03:51
  • @AmitP - Yes, those are two things I don't want to do. Otherwise I would then have to set the non batch metadata datasource all over the place. – DavidR Jun 01 '17 at 03:56

0 Answers0