在这里插入代码片
```#项目服务器配置
spring:
datasource:
master:
jdbc-url: jdbc:mysql://localhost:****/db_**?allowMultiQueries=true&useUnicode=true&characterEncoding=UTF-8&useSSL=true
username: root
password: ****
initialSize: 1
minIdle: 5
maxActive: 100
maxWait: 60000
testWhileIdle: true
testOnReturn: false
testOnBorrow: false
validationQuery: SELECT 1
removeAbandoned: true
removeAbandonedTimeout: 1800
logAbandoned: true
filters: mergeStat
timeBetweenEvictionRunsMillis: 60000
minEvictableIdleTimeMillis: 25200000
other:
jdbc-url: jdbc:sqlserver://192.168.*.***;databasename=****
username: **
password: ******
initialSize: 1
minIdle: 5
maxActive: 100
maxWait: 60000
testWhileIdle: true
testOnReturn: false
testOnBorrow: false
validationQuery: SELECT 1s
removeAbandoned: true
removeAbandonedTimeout: 1800
logAbandoned: true
filters: mergeStat
timeBetweenEvictionRunsMillis: 60000
minEvictableIdleTimeMillis: 25200000
redis:
host: 127.0.0.1
password:
jedis:
pool:
min-idle: 0
max-idle: 20
# max-wait: 5000
max-active: 100
主数据源配置
package com.**.admin.config;
import org.apache.ibatis.session.SqlSessionFactory;
import org.mybatis.spring.SqlSessionFactoryBean;
import org.mybatis.spring.SqlSessionTemplate;
import org.mybatis.spring.annotation.MapperScan;
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 org.springframework.core.io.support.PathMatchingResourcePatternResolver;
import org.springframework.jdbc.datasource.DataSourceTransactionManager;
import javax.sql.DataSource;
@Configuration
@MapperScan(basePackages = "com.**.dao.mapper",sqlSessionFactoryRef = "masterSqlSessionFactory")
public class MybatisDbMasterConfig {
@Primary
@Bean(name = "masterDataSource")
@ConfigurationProperties(prefix = "spring.datasource.master")
public DataSource dataSource(){
return DataSourceBuilder.create().build();
}
@Primary
@Bean(name = "masterSqlSessionFactory")
public SqlSessionFactory sqlSessionFactory(@Qualifier("masterDataSource") DataSource dataSource)throws Exception{
SqlSessionFactoryBean factoryBean = new SqlSessionFactoryBean();
factoryBean.setDataSource(dataSource);
factoryBean.setTypeAliasesPackage("com.****.dao.entity");
factoryBean.setMapperLocations(new PathMatchingResourcePatternResolver().getResources("classpath:com/mj/dao/mapper/*Mapper.xml"));
return factoryBean.getObject();
}
//配置事务管理
@Primary
@Bean(name = "masterTransactionManager")
public DataSourceTransactionManager transactionManager(@Qualifier("masterDataSource") DataSource dataSource){
return new DataSourceTransactionManager(dataSource);
}
@Bean(name = "masterSqlSessionTemplate")
@Primary
public SqlSessionTemplate testSqlSessionTemplate(
@Qualifier("masterSqlSessionFactory