0

I am new to Spring Boot and trying to configure and access two databases using Spring JDBC. Can someone help me here? I have one local database (MySQL) and another on AWS RDS (MySQL). I have configured application.yml with two data sources, but whenever I run the application, it only connects to the last database configured in application.yml. I want to connect to both database as from one database I need to get information and process and put logs in AWS RDS. Can someone help me here?

This is my Dbconfig file

@Bean(name = "rdsDatasource")
@ConfigurationProperties("spring.datasource.rds")
public DataSource rdsDatasource() {
   return DataSourceBuilder.create().build();
}

@Bean
public NamedParameterJdbcOperations    namedParameterJdbcOperations(@Qualifier("rdsDatasource") DataSource rdsDbDataSource) {
return new NamedParameterJdbcTemplate(rdsDbDataSource);
}

application.yml

datasource:
    local:
    url: jdbc:mysql://localhost:3306/test
    username: test
    password: test
    port: 3306
  rds:
    url: jdbc:mysql://aws-rds/test
    username: test
    password: test
    port: 3306.
  • Does this answer your question? [Spring Boot Configure and Use Two DataSources](https://stackoverflow.com/questions/30337582/spring-boot-configure-and-use-two-datasources) – pringi Jan 07 '22 at 14:12

0 Answers0