package com.hx.other.service.config;
|
|
import org.springframework.beans.factory.annotation.Qualifier;
|
import org.springframework.boot.context.properties.ConfigurationProperties;
|
import org.springframework.boot.jdbc.DataSourceBuilder;
|
import org.springframework.context.annotation.Bean;
|
import org.springframework.context.annotation.Configuration;
|
import org.springframework.context.annotation.Primary;
|
|
import javax.sql.DataSource;
|
|
/**
|
* 数据源配置
|
* @Author: cmg
|
* @Date: 2023/5/5 10:56
|
*/
|
@Configuration
|
public class DataSourceConfig {
|
|
@Bean(name = "readDataSource")
|
@Qualifier("readDataSource")
|
@ConfigurationProperties(prefix = "spring.datasource.read")
|
public DataSource readDataSource()
|
{
|
return DataSourceBuilder.create().build();
|
}
|
|
@Bean(name = "writeDataSource")
|
@Qualifier("writeDataSource")
|
@ConfigurationProperties(prefix = "spring.datasource.write")
|
@Primary
|
public DataSource writeDataSource()
|
{
|
return DataSourceBuilder.create().build();
|
}
|
}
|