日常学习中遇到得一个问题,mybatis-plus多数据源的配置按照官方文档都已配置成功,可是springbootTest测试时发现无法正常的切换的切换数据源,一直使用的是默认数据源,在查看了一些大佬的文章后,发现都没有这样的问题出现,要么是自己新增注解实现多数据源的注入,要么在mybatis-plus的配置类中配置或者使用切面的方式实现多数据源的操作,可是一想好像远离了plus的的最开始的想法,反而更加复杂了,然后突发奇想,将controller service都写上,然后使用注解@DS切换数据源,结果直接成功了,具体原因目前由于本人技术还不到位还做不到原因的解释,后续会继续研究,如果有最新的成果,会在评论区写上,如果有哪位大神知道原因的话,麻烦告知下,下面是配置的代码:
pom依赖:
yml配置文件: