Springcloud多模块整合mybatis-plus

时间:2021-06-22 17:47:51   收藏:0   阅读:0

最近打算搭一个spring-cloud的框架,并打算整合mybatis-plus的插件。然后却遇到了一个消耗了我十几个钟的问题。

出现的问题是:

org.apache.ibatis.binding.BindingException: Invalid bound statement (not found): com.bestlmc.lihuamao.services.service.ITMenuService.getTest

这里显示的是绑定的问题,然后我查了一下官方文档,一般是以下几个问题导致:

https://mp.baomidou.com/guide/faq.html#出现-invalid-bound-statement-not-found-异常

也有人说配置文件中,mybatis要改成mybatis-plus:

mybatis-plus:
mapper-locations: classpath*:/mapper/*Mapper.xml
type-aliases-package: com.bestlmc.lihuamao.commons.been    # 所有Entity别名类所在包

诸如此类,终究还是没有效果。

但是我自己用springboot但模块整合mybatis-plus使用的话还是正常的。然而,这跟我想要的效果不一样。出于解耦的思想,我想要将service层和mapper层的代码分离出来,作为一个公用的模块。这样便可以减少代码的冗余。

只是按照这样的模块搭建,能成功运行,访问接口的时间就会报org.apache.ibatis.binding.BindingException: Invalid bound statement (not found): 这样的错误。

最终检查多次之后,发现了问题出在启动类中:

@SpringBootApplication
@EnableOpenApi
@MapperScan(basePackages = {
       "com.bestlmc.lihuamao.admin.config",
       "com.bestlmc.lihuamao.admin.controller",
       "com.bestlmc.lihuamao.services.service",
       "com.bestlmc.lihuamao.commons.config"})
public class AdminApplication {
   public static void main(String[] args) {
       SpringApplication.run(AdminApplication.class,args);
  }
}

@MapperScan只是扫描mapper的实现类

这里应该使用的是@ComponentScan,@ComponentScan适合扫描各类的been。

最终将MapperScan更换为ComponentScan,解决问题。

@SpringBootApplication
@EnableOpenApi
@ComponentScan(basePackages = {
       "com.bestlmc.lihuamao.admin.config",
       "com.bestlmc.lihuamao.admin.controller",
       "com.bestlmc.lihuamao.services.service",
       "com.bestlmc.lihuamao.commons.config"})
public class AdminApplication {
   public static void main(String[] args) {
       SpringApplication.run(AdminApplication.class,args);
  }
}

详细代码可以查看我的开源项目https://gitee.com/bestlmc/lihuamao_blog

 

评论(0
© 2014 mamicode.com 版权所有 京ICP备13008772号-2  联系我们:gaon5@hotmail.com
迷上了代码!