package com.yihu.wlyy.statistics.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 Administrator on 2016.10.20.
 * 多数据源配置
 */
@Configuration
public class DataSourceConfig {
    /**
     *  主数据源
     * @return
     */
    @Bean(name = "primaryReadWrite")
    @Primary//主库 默认不写名字用这个
    @ConfigurationProperties(prefix="spring.datasource.primaryReadWrite")
    public DataSource primaryReadWriteDataSource() {
        return DataSourceBuilder.create().build();
    }

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


}
