admin管理员组

文章数量:1530842

新建springboot项目启动时出现报错:Consider defining a bean of type ‘com.project.springboot.mapper.UserMapper’ in your configuration.

报错提示没有扫描到UserMapper接口类,查询到是Mapper中的UserMapper接口类没有添加Mapper注解导致
解决方法一:
在接口列上添加@Mapper注解

@Mapper
public interface UserMapper {}

解决方法二:
在运行主类上添加注解@MapperScan,扫描UserMapper所在包Mapper
@MapperScan有两种写法,使用时采用一种

public @interface MapperScan {
    String[] value() default {};

    String[] basePackages() default {};
    }

value类型:

@MapperScan("com.project.springboot.mapper")
public class AppRun {
    public static void main(String[] args) {
        SpringApplication.run(AppRun.class, args);
    }
}

basePackages类型:

@MapperScan(basePackages = "com.project.springboot.mapper")
public class AppRun {
    public static void main(String[] args) {
        SpringApplication.run(AppRun.class, args);
    }
}

本文标签: typeProjectdefiningbeanUserMapper