baomidou / mybatis-plus

An powerful enhanced toolkit of MyBatis for simplify development
https://baomidou.com
Apache License 2.0
16.3k stars 4.3k forks source link

mybatis-plus与shardingsphere同时使用冲突致启动错误!! #1340

Closed przygrubyu5 closed 5 years ago

przygrubyu5 commented 5 years ago

当前使用版本(必须填写清楚,否则不予处理)

mybatis-plus 3.1.0 shardingsphere 4.0.0-RC1 spring-boot 2.1.5.RELEASE

该问题是怎么引起的?*([最新版](https://search.maven.org/search?q=g:com.baomidou%20a:mybatis-)上已修复的会直接close掉)**

  1. 如果纯使用shardingsphere +mybatis,不会出问题
  2. 引入了mybatis-plus-boot-starter后直接冲突(此时还没有将mapper改造成mybatis-plus),这时在配置文件排除com.baomidou.mybatisplus.autoconfigure.MybatisPlusAutoConfiguration后项目又可以正常运行
  3. 将mapper改造成mybatis-plus后报错找不到sqlsessionfactory,如果不排除MybatisPlusAutoConfiguration,shardingsphere 的database不能创建已经存在数据源,这时只能增加配置 spring.main.allow-bean-definition-overriding=true来强制覆盖database
  4. 如果不使用spring.main.allow-bean-definition-overriding=true,只能将org.apache.shardingsphere.shardingjdbc.spring.boot.SpringBootConfiguration排除,在项目里重新建立一个一模一样的,将databae()方法重命名来解决

如何能保证分库分表与mybatis-plus同时使用不冲突,个人觉得上述3、4方法不是太好,如何以最好的方法来处理,还需要请教一下!

重现步骤

  1. 项目引入mybatis-plus
  2. 项目引入shardingsphere
  3. 使用mybatis-plus的mapper
  4. 启动项目

报错信息

  1. 同时引入后未将mapper改成mybatis-plus方式 image

  2. 同时引入后将mapper改成mybatis-plus方式 image image image

miemieYaho commented 5 years ago

自行解决

woshixhs commented 4 years ago

这个问题如何解决?

woshixhs commented 4 years ago

@miemieYaho

przygrubyu5 commented 4 years ago

@woshixhs 将springboot导入自动配置顺序改成 shardingjdbc - mybatis

woshixhs commented 4 years ago

@liulipengju 还是谢谢,我自己已经解决

junwangit commented 4 years ago

自己已经解决

如何解决?有啥好的方案

przygrubyu5 commented 4 years ago

@Import({ SpringBootConfiguration.class, MybatisPlusAutoConfiguration.class, DruidDataSourceAutoConfigure.class })

BingYu-track commented 3 years ago

怎么弄你的呀?我排除了还是不行

1425080898 commented 4 months ago

怎么解决的

shnehna commented 1 month ago

有没有好大哥给个转信啊,愁死人了。告诉我怎么解决的呗。