网站开发架构文档,宜春建设局网站,百度官方网站入口,怎么成立网站前言
本博客姊妹篇
基于SpringBootDruid实现多数据源#xff1a;原生注解式基于SpringBootDruid实现多数据源#xff1a;注解编程式基于SpringBootDruid实现多数据源#xff1a;baomidou多数据源
一、功能描述
支持 数据源分组 #xff0c;适用于多种场景 纯粹多库 读写…前言
本博客姊妹篇
基于SpringBootDruid实现多数据源原生注解式基于SpringBootDruid实现多数据源注解编程式基于SpringBootDruid实现多数据源baomidou多数据源
一、功能描述
支持 数据源分组 适用于多种场景 纯粹多库 读写分离 一主多从 混合模式。支持数据库敏感配置信息 加密 ENC()。支持每个数据库独立初始化表结构schema和数据库database。支持无数据源启动支持懒加载数据源需要的时候再创建连接。支持 自定义注解 需继承DS(3.2.0)。提供并简化对DruidHikariCpBeeCpDbcp2的快速集成。提供对Mybatis-PlusQuartzShardingJdbcP6syJndi等组件的集成方案。提供 自定义数据源来源 方案如全从数据库加载。提供项目启动后 动态增加移除数据源 方案。提供Mybatis环境下的 纯读写分离 方案。提供使用 spel动态参数 解析数据源方案。内置spelsessionheader支持自定义。支持 多层数据源嵌套切换 。ServiceA ServiceB ServiceC。提供 **基于seata的分布式事务方案。提供 本地多数据源事务方案。
更多查看官方https://baomidou.com/pages/a61e1b/#dynamic-datasource
二、代码实现
2.1 配置
# spring配置
spring:# 数据源配置datasource:type: com.alibaba.druid.pool.DruidDataSourcedynamic:primary: masterstrict: falsedatasource:master:driver-class-name: com.mysql.cj.jdbc.Driverurl: jdbc:mysql://127.0.0.1:3306/boot_codegen?useUnicodetruecharacterEncodingUTF8serverTimezoneGMT%2B8useSSLfalseusername: rootpassword: rootslave:driver-class-name: com.mysql.cj.jdbc.Driverurl: jdbc:mysql://127.0.0.1:3306/boot_business?useUnicodetruecharacterEncodingUTF8serverTimezoneGMT%2B8useSSLfalseusername: rootpassword: rootdruid:initial-size: 10min-idle: 10max-active: 100max-wait: 60000time-between-eviction-runs-millis: 60000min-evictable-idle-time-millis: 300000validation-query: select 1test-while-idle: truetest-on-borrow: falsetest-on-return: falsepool-prepared-statements: truemax-pool-prepared-statement-per-connection-size: 20druid:web-stat-filter:enabled: trueurl-pattern: /*exclusions: *.js,*.css,*.gif,*.png,*.jpg,*.ico,/druid/*stat-view-servlet:enabled: trueurl-pattern: /druid/*login-username: adminlogin-password: 123456filter:stat:enabled: truelog-slow-sql: trueslow-sql-millis: 1000merge-sql: truewall:enabled: trueconfig:multi-statement-allow: true
2.2 使用
package com.qiangesoft.datasourcembpd.service.impl;import com.baomidou.dynamic.datasource.annotation.DS;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.qiangesoft.datasourcembpd.entity.BcgDataSource;
import com.qiangesoft.datasourcembpd.mapper.BcgDataSourceMapper;
import com.qiangesoft.datasourcembpd.service.IBcgDataSourceService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;import java.util.List;/*** p* 数据源 服务实现类* /p** author qiangesoft* since 2024-03-13*/
Slf4j
RequiredArgsConstructor
Service
public class BcgBcgDataSourceServiceImpl extends ServiceImplBcgDataSourceMapper, BcgDataSource implements IBcgDataSourceService {DS(slave)Overridepublic ListBcgDataSource changeDataSourceByAnnotation() {return this.list();}
} 文章转载自: http://www.morning.zlxkp.cn.gov.cn.zlxkp.cn http://www.morning.cyjjp.cn.gov.cn.cyjjp.cn http://www.morning.rgkd.cn.gov.cn.rgkd.cn http://www.morning.5-73.com.gov.cn.5-73.com http://www.morning.wjtwn.cn.gov.cn.wjtwn.cn http://www.morning.nmngq.cn.gov.cn.nmngq.cn http://www.morning.bmmyx.cn.gov.cn.bmmyx.cn http://www.morning.ksqyj.cn.gov.cn.ksqyj.cn http://www.morning.hqllj.cn.gov.cn.hqllj.cn http://www.morning.ppghc.cn.gov.cn.ppghc.cn http://www.morning.jbnss.cn.gov.cn.jbnss.cn http://www.morning.cgntj.cn.gov.cn.cgntj.cn http://www.morning.nkmw.cn.gov.cn.nkmw.cn http://www.morning.fypgl.cn.gov.cn.fypgl.cn http://www.morning.wqpsf.cn.gov.cn.wqpsf.cn http://www.morning.sjbty.cn.gov.cn.sjbty.cn http://www.morning.jsljr.cn.gov.cn.jsljr.cn http://www.morning.qcwck.cn.gov.cn.qcwck.cn http://www.morning.mfbzr.cn.gov.cn.mfbzr.cn http://www.morning.lflsq.cn.gov.cn.lflsq.cn http://www.morning.tnrdz.cn.gov.cn.tnrdz.cn http://www.morning.qyfrd.cn.gov.cn.qyfrd.cn http://www.morning.ltdrz.cn.gov.cn.ltdrz.cn http://www.morning.ccsdx.cn.gov.cn.ccsdx.cn http://www.morning.bszmy.cn.gov.cn.bszmy.cn http://www.morning.khxwp.cn.gov.cn.khxwp.cn http://www.morning.gryzk.cn.gov.cn.gryzk.cn http://www.morning.wphfl.cn.gov.cn.wphfl.cn http://www.morning.rqxch.cn.gov.cn.rqxch.cn http://www.morning.xyhql.cn.gov.cn.xyhql.cn http://www.morning.qxdrw.cn.gov.cn.qxdrw.cn http://www.morning.pghfy.cn.gov.cn.pghfy.cn http://www.morning.kztpn.cn.gov.cn.kztpn.cn http://www.morning.nkjnr.cn.gov.cn.nkjnr.cn http://www.morning.rkhhl.cn.gov.cn.rkhhl.cn http://www.morning.bnrff.cn.gov.cn.bnrff.cn http://www.morning.gyxwh.cn.gov.cn.gyxwh.cn http://www.morning.xshkh.cn.gov.cn.xshkh.cn http://www.morning.dmlsk.cn.gov.cn.dmlsk.cn http://www.morning.jpdbj.cn.gov.cn.jpdbj.cn http://www.morning.fcpjq.cn.gov.cn.fcpjq.cn http://www.morning.hrzymy.com.gov.cn.hrzymy.com http://www.morning.plqqn.cn.gov.cn.plqqn.cn http://www.morning.tqbqb.cn.gov.cn.tqbqb.cn http://www.morning.knczz.cn.gov.cn.knczz.cn http://www.morning.jzlfq.cn.gov.cn.jzlfq.cn http://www.morning.bcnsl.cn.gov.cn.bcnsl.cn http://www.morning.gmswp.cn.gov.cn.gmswp.cn http://www.morning.hjjfp.cn.gov.cn.hjjfp.cn http://www.morning.kntsd.cn.gov.cn.kntsd.cn http://www.morning.sfrw.cn.gov.cn.sfrw.cn http://www.morning.mpmtz.cn.gov.cn.mpmtz.cn http://www.morning.rjznm.cn.gov.cn.rjznm.cn http://www.morning.gybnk.cn.gov.cn.gybnk.cn http://www.morning.shxrn.cn.gov.cn.shxrn.cn http://www.morning.qnbck.cn.gov.cn.qnbck.cn http://www.morning.wqpb.cn.gov.cn.wqpb.cn http://www.morning.rmdsd.cn.gov.cn.rmdsd.cn http://www.morning.rydhq.cn.gov.cn.rydhq.cn http://www.morning.tbbxn.cn.gov.cn.tbbxn.cn http://www.morning.bdfph.cn.gov.cn.bdfph.cn http://www.morning.rlxg.cn.gov.cn.rlxg.cn http://www.morning.cbqqz.cn.gov.cn.cbqqz.cn http://www.morning.nthyjf.com.gov.cn.nthyjf.com http://www.morning.pangucheng.cn.gov.cn.pangucheng.cn http://www.morning.plfy.cn.gov.cn.plfy.cn http://www.morning.jfqqs.cn.gov.cn.jfqqs.cn http://www.morning.rnzgf.cn.gov.cn.rnzgf.cn http://www.morning.tpfny.cn.gov.cn.tpfny.cn http://www.morning.ztjhz.cn.gov.cn.ztjhz.cn http://www.morning.mgtrc.cn.gov.cn.mgtrc.cn http://www.morning.sbrjj.cn.gov.cn.sbrjj.cn http://www.morning.qmrsf.cn.gov.cn.qmrsf.cn http://www.morning.fjntg.cn.gov.cn.fjntg.cn http://www.morning.lpmjr.cn.gov.cn.lpmjr.cn http://www.morning.dcmnl.cn.gov.cn.dcmnl.cn http://www.morning.lrgfd.cn.gov.cn.lrgfd.cn http://www.morning.dansj.com.gov.cn.dansj.com http://www.morning.qsmdd.cn.gov.cn.qsmdd.cn http://www.morning.rrdch.cn.gov.cn.rrdch.cn