springbootmybaits_day2

1 多数据源

公司可能分为两个库,一个数据库用来存放共同配置文件,一个数据库垂直业务数据库。

在一个项目中有多少数据源,(连接不同的jdbc),理论上是无限大,具体根据内存来决定,8g配24个数据源。

2在一个项目中多数据源该如何划分:分包名(业务)||注解方式

分包:

com.xiangwen.test1----datasource1
com.xiangwen.test2----datasource2

(注意:在springboot1.5的时候,没有默认指定数据源,加上@Primary

在多数据源事物的时候@Transactiona(transactionManager = "test2TransactionManager"),指定具体某个数据源的事物,否则会报错

There was an unexpected error (type=Internal Server Error, status=500).
No qualifying bean of type 'org.springframework.transaction.PlatformTransactionManager' available: expected single matching bean but found 2: test1TransactionManager,test2TransactionManage

l)
注解:

在dao层方法上使用自定义的注解,原理使用aop拦截技术。

@Datesource(ref="datasource1")

3.当一个serve下面由多个数据源的dao操作
传统分布式事务解决方案jta+atomikos将本地事务A和本地事务B....注册同一个全局事务中,@Transactiona()就不需要指定具体哪个事务了。

不适用于电商类型的微服务。

posted @ 2021-03-03 23:43  傲云萧雨  阅读(58)  评论(0编辑  收藏  举报