码迷,mamicode.com
首页 > 数据库 > 详细

Spring Boot Dataway 配置多数据库源

时间:2020-06-08 14:51:33      阅读:360      评论:0      收藏:0      [点我收藏+]

标签:nbsp   config   private   autowired   new   component   auto   jdb   class   

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 配置多数据库源

标签:nbsp   config   private   autowired   new   component   auto   jdb   class   

原文地址:https://www.cnblogs.com/nachdenken/p/13065310.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!