Spring boot - how to configure multiple datasources

后端 未结 3 1339
野性不改
野性不改 2020-12-19 19:48

I am trying to setup multiple data sources(MySql, Postgres & Oracle) using Spring boot. I am not using JPA. Setting up with a JdbcTemplate.

I have tried setting

3条回答
  •  不思量自难忘°
    2020-12-19 20:07

    My setup: spring-boot version 1.2.5.RELEASE

    I succeeded in running a setup like this, with the jdbc being created with the correct DataSources by adding a @Qualifier in each JDBC method creation

    So, for every JDBC method you should match the qualifying datasource like this

    @Bean(name = "dJdbc")
    public JdbcTemplate drupalJdbcTemplate(@Qualifier("dMySql") DataSource dMySql) {
        return new JdbcTemplate(dMySql);
    }
    

    No matter you choose for @Primary, using the @Qualifier for every JDBC should work good. Autowiring jdbcTemplates in repositories, and using @Qualifier for them is ok also.

提交回复
热议问题