新建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);
}
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)