guang
2023-05-05 566411019444e53ca143298ee490d33cf510e28c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
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();
    }
}