提交 9e41ab8c 编写于 作者: zhouweidong's avatar zhouweidong

mp动态数据源

上级 0b172175
<#ibiztemplate>
TARGET=PSSYSAPP
</#ibiztemplate>
<#assign bDynamicDS=false>
<#list sys.getAllPSDataEntities() as entity>
<#if (entity.getStorageMode()==1 || entity.getStorageMode()==2) && entity.getDSLink()!='DEFAULT'>
<#assign bDynamicDS=true>
<#break>
</#if>
</#list>
package ${pub.getPKGCodeName()}.${app.getPKGCodeName()?lower_case};
import lombok.extern.slf4j.Slf4j;
......@@ -42,6 +49,9 @@ import java.util.List;
<#if bmogo==false>
org.springframework.boot.autoconfigure.mongo.MongoAutoConfiguration.class,
</#if>
<#if bDynamicDS>
com.alibaba.druid.spring.boot.autoconfigure.DruidDataSourceAutoConfigure.class
</#if>
})
public class ${app.getPKGCodeName()}Application extends WebMvcConfigurerAdapter{
......
<#ibiztemplate>
TARGET=PSSYSTEM
</#ibiztemplate>
<#assign bDynamicDS=false>
<#list sys.getAllPSDataEntities() as entity>
<#if (entity.getStorageMode()==1 || entity.getStorageMode()==2) && entity.getDSLink()!='DEFAULT'>
<#assign bDynamicDS=true>
<#break>
</#if>
</#list>
package ${pub.getPKGCodeName()};
import lombok.extern.slf4j.Slf4j;
......@@ -36,6 +43,9 @@ import java.util.List;
<#if bmogo==false>
org.springframework.boot.autoconfigure.mongo.MongoAutoConfiguration.class,
</#if>
<#if bDynamicDS>
com.alibaba.druid.spring.boot.autoconfigure.DruidDataSourceAutoConfigure.class
</#if>
})
@ComponentScan(basePackages = {"${pub.getPKGCodeName()}"}
// ,excludeFilters={
......
......@@ -21,6 +21,11 @@ import java.io.Serializable;
import com.baomidou.mybatisplus.core.toolkit.Constants;
import com.alibaba.fastjson.JSONObject;
<#if item.getDSLink?? && item.getDSLink()??>
<#if item.getDSLink()!='DEFAULT'>
@com.baomidou.dynamic.datasource.annotation.DS("${item.getDSLink()?lower_case}")
</#if>
</#if>
public interface ${item.getCodeName()}Mapper extends BaseMapper<${item.getCodeName()}>{
<#if item.getAllPSDEDataSets()??>
......
<#ibiztemplate>
TARGET=PSSYSTEM
</#ibiztemplate>
<#assign bDynamicDS=false>
<#list sys.getAllPSDataEntities() as entity>
<#if (entity.getStorageMode()==1 || entity.getStorageMode()==2) && entity.getDSLink()!='DEFAULT'>
<#assign bDynamicDS=true>
<#break>
</#if>
</#list>
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
......@@ -363,6 +370,14 @@ TARGET=PSSYSTEM
</#list>
</#if>
<#if bDynamicDS>
<!-- mp动态数据源 -->
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>dynamic-datasource-spring-boot-starter</artifactId>
</dependency>
</#if>
</dependencies>
</project>
<#ibiztemplate>
TARGET=PSSYSSERVICEAPI
</#ibiztemplate>
<#assign bDynamicDS=false>
<#list sys.getAllPSDataEntities() as entity>
<#if (entity.getStorageMode()==1 || entity.getStorageMode()==2) && entity.getDSLink()!='DEFAULT'>
<#assign bDynamicDS=true>
<#break>
</#if>
</#list>
package ${pub.getPKGCodeName()}.${item.codeName?lower_case};
import lombok.extern.slf4j.Slf4j;
......@@ -45,6 +52,9 @@ import java.util.List;
<#if bmogo==false>
org.springframework.boot.autoconfigure.mongo.MongoAutoConfiguration.class,
</#if>
<#if bDynamicDS>
com.alibaba.druid.spring.boot.autoconfigure.DruidDataSourceAutoConfigure.class
</#if>
})
@Import({
org.springframework.cloud.openfeign.FeignClientsConfiguration.class
......
......@@ -10,6 +10,13 @@ TARGET=PSSYSTEM
<#assign dbPassWord="root">
<#assign dbUrl="jdbc:mysql://127.0.0.1:3306/"+sys.name+"?autoReconnect=true&useUnicode=true&characterEncoding=UTF-8&useOldAliasMetadataBehavior=true">
<#assign dbDriver="com.mysql.jdbc.Driver">
<#assign bDynamicDS=false>
<#list sys.getAllPSDataEntities() as entity>
<#if (entity.getStorageMode()==1 || entity.getStorageMode()==2) && entity.getDSLink()!='DEFAULT'>
<#assign bDynamicDS=true>
<#break>
</#if>
</#list>
<#comment>前端应用微服务平台配置</#comment>
<#if sys.getAllPSDevSlnMSDepApps()??>
<#list sys.getAllPSDevSlnMSDepApps() as depApp>
......@@ -144,32 +151,11 @@ spring:
max-wait: 300ms
max-idle: 16
min-idle: 8
datasource:
username: ${dbUserName}
password: '${dbPassWord}'
url: ${dbUrl}
driver-class-name: ${dbDriver}
filters: stat,wall,log4j2
#配置初始化大小/最小/最大
initial-size: 1
min-idle: 1
max-active: 20
#获取连接等待超时时间
max-wait: 60000
#间隔多久进行一次检测,检测需要关闭的空闲连接
time-between-eviction-runs-millis: 60000
#一个连接在池中最小生存的时间
min-evictable-idle-time-millis: 300000
validation-query: SELECT 1 FROM DUAL
test-while-idle: true
test-on-borrow: false
test-on-return: false
#打开PSCache,并指定每个连接上PSCache的大小。oracle设为true,mysql设为false。分库分表较多推荐设置为false
pool-prepared-statements: false
max-pool-prepared-statement-per-connection-size: 20
isSyncDBSchema: false
defaultSchema: ${dbUserName}
conf: classpath:liquibase/master.xml
<#if bDynamicDS>
<@dynamicDatasourceConfig/>
<#else>
<@singleDatasourceConfig/>
</#if>
#Mybatis-plus配置
mybatis-plus:
......@@ -234,3 +220,82 @@ server:
mime-types: application/javascript,text/css,application/json,application/xml,text/html,text/xml,text/plain
min-response-size: 10240
<#macro singleDatasourceConfig>
datasource:
username: ${dbUserName}
password: '${dbPassWord}'
url: ${dbUrl}
driver-class-name: ${dbDriver}
filters: stat,wall,log4j2
#配置初始化大小/最小/最大
initial-size: 1
min-idle: 1
max-active: 20
#获取连接等待超时时间
max-wait: 60000
#间隔多久进行一次检测,检测需要关闭的空闲连接
time-between-eviction-runs-millis: 60000
#一个连接在池中最小生存的时间
min-evictable-idle-time-millis: 300000
validation-query: SELECT 1 FROM DUAL
test-while-idle: true
test-on-borrow: false
test-on-return: false
#打开PSCache,并指定每个连接上PSCache的大小。oracle设为true,mysql设为false。分库分表较多推荐设置为false
pool-prepared-statements: false
max-pool-prepared-statement-per-connection-size: 20
isSyncDBSchema: false
defaultSchema: ${dbUserName}
conf: classpath:liquibase/master.xml
</#macro>
<#macro dynamicDatasourceConfig>
datasource:
dynamic:
druid: #以下是全局默认值,可以全局更改
filters: stat,wall,log4j2
#配置初始化大小/最小/最大
initial-size: 1
min-idle: 1
max-active: 20
#获取连接等待超时时间
max-wait: 60000
#间隔多久进行一次检测,检测需要关闭的空闲连接
time-between-eviction-runs-millis: 60000
#一个连接在池中最小生存的时间
min-evictable-idle-time-millis: 300000
validation-query: SELECT 1 FROM DUAL
test-while-idle: true
test-on-borrow: false
test-on-return: false
#打开PSCache,并指定每个连接上PSCache的大小。oracle设为true,mysql设为false。分库分表较多推荐设置为false
pool-prepared-statements: false
max-pool-prepared-statement-per-connection-size: 20
datasource:
master:
username: ${dbUserName}
password: '${dbPassWord}'
url: ${dbUrl}
driver-class-name: ${dbDriver}
conf: classpath:liquibase/master.xml
isSyncDBSchema: false
defaultSchema: ${dbUserName}
<#list sys.getAllPSDataEntities() as entity>
<#if (entity.getStorageMode()==1 || entity.getStorageMode()==2) && entity.getDSLink()!='DEFAULT'>
<#assign dbLink=entity.getDSLink()>
<#if !P.exists('dynamicDatasource',dbLink)>
${dbLink}:
username: ${dbUserName}
password: '${dbPassWord}'
url: ${dbUrl}
driver-class-name: ${dbDriver}
conf: classpath:liquibase/master.xml
isSyncDBSchema: false
defaultSchema: ${dbUserName}
</#if>
</#if>
</#list>
</#macro>
Markdown 格式
0% or
您添加了 0 到此讨论。请谨慎行事。
先完成此消息的编辑!
想要评论请 注册