
package com.dashitech.config;

import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.boot.autoconfigure.jdbc.DataSourceBuilder;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;

import javax.sql.DataSource;


/**
 * Created by chi on 2019/9/20.
 */

@Configuration
public class DataSourceConfig {

    /**
     *  数据源1
     */
    @Primary    //配置该数据源为主数据源
    @Bean(name = "mysql1DataSource")
    @Qualifier(value = "mysql1DataSource")  //spring装配bean的唯一标识
    @ConfigurationProperties(prefix = "mysql1.spring.datasource")   //application.properties配置文件中该数据源的配置前缀
    public DataSource mysql1DataSource(){
        return DataSourceBuilder.create().build();
    }

    /**
     *  数据源2
     */

    @Bean(name = "mysql2DataSource")
    @Qualifier(value = "mysql2DataSource")
    @ConfigurationProperties(prefix = "mysql2.spring.datasource")
    public DataSource mysql2DataSource(){
        return DataSourceBuilder.create().build();
    }
}

