Spring+Mybatis多数据源的一种实现方式,支持事务

最近一个项目用到了多个数据库,所以需要实现动态切换数据源来查询数据,这篇文章让我受益匪浅,提供了一种自动切换数据源的思路,但这种方式不支持事务,所以我进一步改进了这个方案,下面直入正题

多数据源配置:

#============================================================================ # DataBaseOne #============================================================================ jdbc.one.driver=com.mysql.jdbc.Driver jdbc.one.url=jdbc:mysql://127.0.0.1:3306/DataBaseOne?useUnicode=true&characterEncoding=UTF-8&allowMultiQueries=true jdbc.one.username=root jdbc.one.password=root ============================================================================= #============================================================================ # DataBaseTwo #============================================================================ jdbc.two.driver=com.mysql.jdbc.Driver jdbc.two.url=jdbc:mysql://127.0.0.1:3306/DataBaseTwo?useUnicode=true&characterEncoding=UTF-8&allowMultiQueries=true jdbc.two.username=root jdbc.two.password=root ============================================================================= #============================================================================ # DataBaseThree #============================================================================ jdbc.three.driver=com.mysql.jdbc.Driver jdbc.three.url=jdbc:mysql://127.0.0.1:3306/DataBaseThree?useUnicode=true&characterEncoding=UTF-8&allowMultiQueries=true jdbc.three.username=root jdbc.mysql.password=root ============================================================================= #============================================================================ # 通用配置 #============================================================================ jdbc.initialSize=5 jdbc.minIdle=5 jdbc.maxIdle=20 jdbc.maxActive=100 jdbc.maxWait=100000 jdbc.defaultAutoCommit=false jdbc.removeAbandoned=true jdbc.removeAbandonedTimeout=600 jdbc.testWhileIdle=true jdbc.timeBetweenEvictionRunsMillis=60000 jdbc.numTestsPerEvictionRun=20 jdbc.minEvictableIdleTimeMillis=300000

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/wpjdjf.html