Spring Boot Dataway 配置多数据库源

1、配置文件

spring.second-datasource.driver-class-name=
spring.second-datasource.jdbc-url=
spring.second-datasource.username=
spring.second-datasource.password=
#注意jdbc-url与url的区别:
spring.datasource.driver-class-name=
spring.datasource.jdbc-url=
spring.datasource.username=
spring.datasource.password

2、配置类

@Configuration
public class DataSourceConfiguration {
    @Bean
    @Primary
    @ConfigurationProperties(prefix = "spring.datasource")
    public DataSource primaryDataSource() {
        return DataSourceBuilder.create().build();
    }
    
    @Bean(name = "datasourceB")
    @ConfigurationProperties(prefix = "spring.second-datasource")
    public DataSource secondDataSource() {
        return DataSourceBuilder.create().build();
    }
}

3、使用

@DimModule
@Component
public class TestModule implements SpringModule {

    @Autowired
    private DataSource dataSource = null;
    @Autowired
    @Qualifier("datasourceB ")
    private DataSource datasourceB = null;
    
    @Override
    public void loadModule(ApiBinder apiBinder) throws Throwable {

        apiBinder.installModule(new JdbcModule(Level.Full, this.dataSource)); //默认数据源
        apiBinder.installModule(new JdbcModule(Level.Full, "datasourceB ", this.datasourceB )); // 数据源B}

}

 

Spring Boot Dataway 配置多数据库源

上一篇:Oracle数据库基本sql语句


下一篇:SQL SERVER 和 MY SQL 怎么选择