I've created a Spring batch application using Spring boot, and I have a Job
with 9 steps. These steps are using a DataSource
which I created its bean in a configuration file as follows:
@Configuration
public class DatabaseConfig {
@ConfigurationProperties(prefix = "spring.datasource")
@Bean
@Primary
public DataSource dataSource(){
return DataSourceBuilder.create().build();
}
}
This DataSource
is using properties declared in the application.yml
file:
spring:
datasource:
url: jdbc:mysql://localhost:3306/db_01?zeroDateTimeBehavior=convertToNull
username: xxxx
password: ****
So far, all works as expected.
What I want to do, is that I have 4 databases parameterized in a 5th database (db_settings), which I select using an SQL query. This query will return the 4 databases with their usernames and passwords as follows:
+--------+-----------------------------------+-----------------+-----------------+
| id | url | username_db | password_db |
+--------+-----------------------------------+-----------------+-----------------+
| 243 | jdbc:mysql://localhost:3306/db_01 | xxxx | **** |
| 244 | jdbc:mysql://localhost:3306/db_02 | xxxx | **** |
| 245 | jdbc:mysql://localhost:3306/db_03 | xxxx | **** |
| 247 | jdbc:mysql://localhost:3306/db_04 | xxxx | **** |
+--------+-----------------------------------+-----------------+-----------------+
So instead of running the steps using the database declared in 'application.yml', I want to run them on all the 4 databases. And considering the volume processed, it is necessary to be able to launch the batch processing on these databases in parallel.
Does anyone know how to implement this?