I am trying to add a second data-source to a spring Boot project.
The primary connection is configured using spring.datasource.* properties, which I are getting configured using DataSourceAutoConfiguration. The entire project makes use of JdbcTemplate and no JPA config is required.
If I am creating an @Configuration for secondary datasource and excluding default datasource injected packages, the secondary configuration is overriding the default datasource which will be configured using datasourceautoconfiguration class
Is what I am trying to do possible?
I tried building both datasources seperately and autowiring the JdbcTemplate based on qualifier -> This works.
I tried only binding the second datatsource and autowired using qualifier -> this takes second datasource for the primary jdbcTemplate as well. Since first source is configured using DataSourceAutoConfiguration, I am uanble to bind this source to a template.
P.S: sorry I cannot paste the code here and default config should be untouched.
I could not achieve the above requirement using
@Configurationbut the alternative solution what I did was, build theDataSourcein a@Serviceand bind that to the local JdbcTemplate where I wanted to use that secondary connectionEdit: As per @M.Deniums' suggestion in the comment, this should not be done.