1、问题描述:找不到Mapper文件

1.1、原因:

没有扫描到相应的包,导致出现错误

  1. APPLICATION FAILED TO START
  2. ***************************
  3. Description:
  4. Field loginService in com.ck.shirodemo.controller.LoginController required a bean of type 'com.ck.shirodemo.dao.SysUserMapper' that could not be found.
  5. The injection point has the following annotations:
  6. - @org.springframework.beans.factory.annotation.Autowired(required=true)
  7. Action:
  8. Consider defining a bean of type 'com.ck.shirodemo.dao.SysUserMapper' in your configuration.
  9. Process finished with exit code 0

1.2、解决办法:

在启动类上加上 @MapperScan("扫描的包") ,一般是扫描dao层文件夹即可,具体看项目搭建架构。

  1. import org.mybatis.spring.annotation.MapperScan;
  2. import org.springframework.boot.SpringApplication;
  3. import org.springframework.boot.autoconfigure.SpringBootApplication;
  4. @SpringBootApplication
  5. @MapperScan("com.ck.shirodemo.dao")
  6. public class ShiroDemoApplication {
  7. public static void main(String[] args) {
  8. SpringApplication.run(ShiroDemoApplication.class, args);
  9. }
  10. }