Consider defining a bean of type 'XX.XX.XX.XX.mapper.XXMapper' in your configuration.

 

今天构建一个springboot 项目,采用mybatis+mysql 然后就出现了这种错误....浪费我半天时间

 1 Description:
 2 
 3 Field loginLogMapper in com.guoll.modules.sysmanage.service.PassagewayService required a bean of type ‘com.guoll.modules.sysmanage.mapper.LoginLogMapper‘ that could not be found.
 4 
 5 The injection point has the following annotations:
 6 - @org.springframework.beans.factory.annotation.Autowired(required=true)
 7 
 8 
 9 Action:
10 
11 Consider defining a bean of type ‘com.guoll.modules.sysmanage.mapper.LoginLogMapper‘ in your configuration.
12 
13 
14 Process finished with exit code 0

错误原因:是由于springboot 扫描不到 mapper

 

解决方案:

 第一种:在mapper包下类配置@Mapper 注解

Consider defining a bean of type 'XX.XX.XX.XX.mapper.XXMapper' in your configuration.

第二种:在springboot 启动类上配置包扫描@ComponentScan()

Consider defining a bean of type 'XX.XX.XX.XX.mapper.XXMapper' in your configuration.

 

第三种:在springboot 启动类上配置Mapper扫描@MapperScan(注意:必须将路径指定到 xxx.xxx.xxx.mapper 包为止,否则依旧扫描不到) 多个mapper路径 可以以 @MapperScan({mapper1路径,mapper2路径})

这种本人亲测


 Consider defining a bean of type 'XX.XX.XX.XX.mapper.XXMapper' in your configuration.

第四种解决方法,就是将 spring boot启动类方法mapper上级,这样也可以扫描到

 

工作中出了问题,解决时间太久,记录一下

 

Consider defining a bean of type 'XX.XX.XX.XX.mapper.XXMapper' in your configuration.

上一篇:百度编辑器实现WORD粘贴图片自动上传


下一篇:js 关闭MediaDevices.getUserMedia()