用友客开

SpringBoot+Mybatis-plus多模块项目,启动后提示找不到XxxMapper或者BaseMapper

时间:2022-09-06 15:16:09   作者:五块二   来源:转载   阅读:87   评论:0

一、问题背景

SpringBoot拆分为多模块项目(按不同形式拆分)
按层次拆分:controller一个项目、service一个项目、dao(mapper)一个项目
按业务拆分:一个业务模块拆成一个项目(包含该业务的controller、service、dao等)
拆分完成,启动原来的Application后,提示 APPLICATION FAILED TO START

二、问题现象

Description:

Field userMapper in com.fanzyx.crane.framework.security.service.JwtUserDetailsService required a bean of type 'com.fanzyx.xx.mapper.XxxrMapper' that could not be found.

The injection point has the following annotations:
- @org.springframework.beans.factory.annotation.Autowired(required=true)

Action:

Consider defining a bean of type 'com.fanzyx.xx.mapper.XxxrMapper' in your configuration.

或者提示找不到Mybatis-plus 的BaseMapper中的某个方法(你调用的方法)

三、问题原因

先排查下包引用是否冲突,如果没冲突再看下面

Application中没有配置mapper扫描的基础包路径,就只会在当前模块下寻找

e.g.

@SpringBootApplication()
public class XxxApplication {
    public static void main(String[] args) {
        SpringApplication.run(XxxApplication.class,args);
    }
}

四、解决方案

在XxxApplication(启动类) 上增加注解并加入扫描基础路径

// 多模块项目需要配置扫描基础包,否则会无法装载其他模块的类
@SpringBootApplication(scanBasePackages = {"com.fanzyx.xx"})
// 一定要配置到具体路径,中间 ** 可以匹配多层级目录,一个 * 只能匹配单层级目录
//@MapperScan(basePackages = {"com.fanzyx.xx.**.mapper"})
public class XxxApplication{
    public static void main(String[] args) {
        SpringApplication.run(XxxApplication.class,args);
    }
}

转自:https://www.cnblogs.com/fanzyx/p/15659215.html

 

1、官方公众号:尘果科技
2、本站地址:www.5kuai2.com

3、资源部分来源于网络,如有侵权,请联系QQ827566124进行删除处理。



                                          

                                      
                 

相关评论
阅读排行
栖霞区尘果科技工作室版权所有  苏ICP备2022021227号-1