当前使用版本(必须填写清楚,否则不予处理)
mybatis-plus 3.1.0 shardingsphere 4.0.0-RC1 spring-boot 2.1.5.RELEASE
该问题是怎么引起的?(最新版上已修复的会直接close掉)
- 如果纯使用shardingsphere +mybatis,不会出问题
- 引入了mybatis-plus-boot-starter后直接冲突(此时还没有将mapper改造成mybatis-plus),这时在配置文件排除com.baomidou.mybatisplus.autoconfigure.MybatisPlusAutoConfiguration后项目又可以正常运行
- 将mapper改造成mybatis-plus后报错找不到sqlsessionfactory,如果不排除MybatisPlusAutoConfiguration,shardingsphere 的database不能创建已经存在数据源,这时只能增加配置 spring.main.allow-bean-definition-overriding=true来强制覆盖database
- 如果不使用spring.main.allow-bean-definition-overriding=true,只能将org.apache.shardingsphere.shardingjdbc.spring.boot.SpringBootConfiguration排除,在项目里重新建立一个一模一样的,将databae()方法重命名来解决
如何能保证分库分表与mybatis-plus同时使用不冲突,个人觉得上述3、4方法不是太好,如何以最好的方法来处理,还需要请教一下!
重现步骤
- 项目引入mybatis-plus
- 项目引入shardingsphere
- 使用mybatis-plus的mapper
- 启动项目
报错信息
-
同时引入后未将mapper改成mybatis-plus方式
-
同时引入后将mapper改成mybatis-plus方式
Comment From: miemieYaho
自行解决
Comment From: woshixhs
这个问题如何解决?
Comment From: woshixhs
@miemieYaho
Comment From: przygrubyu5
@woshixhs 将springboot导入自动配置顺序改成 shardingjdbc - mybatis
Comment From: woshixhs
@liulipengju 还是谢谢,我自己已经解决
Comment From: junwangit
自己已经解决
如何解决?有啥好的方案
Comment From: przygrubyu5
@Import({ SpringBootConfiguration.class, MybatisPlusAutoConfiguration.class, DruidDataSourceAutoConfigure.class })
Comment From: BingYu-track
怎么弄你的呀?我排除了还是不行
Comment From: 1425080898
怎么解决的
Comment From: shnehna
有没有好大哥给个转信啊,愁死人了。告诉我怎么解决的呗。