guang
2023-05-06 7201205af85508421037119ba66b3a6a48de61ec
提交 | 用户 | age
566411 1 package com.hx.other.service.config;
G 2
720120 3 import com.alibaba.druid.pool.DruidDataSource;
G 4 import com.github.pagehelper.PageInterceptor;
5 import org.apache.ibatis.plugin.Interceptor;
6 import org.apache.ibatis.session.SqlSessionFactory;
7 import org.mybatis.spring.SqlSessionFactoryBean;
566411 8 import org.springframework.beans.factory.annotation.Qualifier;
720120 9 import org.springframework.beans.factory.annotation.Value;
566411 10 import org.springframework.boot.context.properties.ConfigurationProperties;
G 11 import org.springframework.boot.jdbc.DataSourceBuilder;
12 import org.springframework.context.annotation.Bean;
13 import org.springframework.context.annotation.Configuration;
14 import org.springframework.context.annotation.Primary;
720120 15 import org.springframework.core.io.Resource;
G 16 import org.springframework.core.io.support.PathMatchingResourcePatternResolver;
17 import org.springframework.core.io.support.ResourcePatternResolver;
566411 18
G 19 import javax.sql.DataSource;
720120 20 import java.io.IOException;
G 21 import java.util.ArrayList;
22 import java.util.Arrays;
23 import java.util.List;
24 import java.util.Properties;
566411 25
G 26 /**
27  * 数据源配置
28  * @Author: cmg
29  * @Date: 2023/5/5 10:56
30  */
31 @Configuration
32 public class DataSourceConfig {
720120 33
G 34     @Value("${mybatis.mapperLocations}")
35     private String writeMapperLocatioin;
566411 36
G 37     @Bean(name = "readDataSource")
38     @Qualifier("readDataSource")
39     @ConfigurationProperties(prefix = "spring.datasource.read")
40     public DataSource readDataSource()
41     {
42         return DataSourceBuilder.create().build();
43     }
44
45     @Bean(name = "writeDataSource")
46     @Qualifier("writeDataSource")
47     @ConfigurationProperties(prefix = "spring.datasource.write")
48     @Primary
49     public DataSource writeDataSource()
50     {
720120 51         return new DruidDataSource();
566411 52     }
G 53 }