最近在做spring-boot项目的时候出现了找不到mapper接口的问题,控制台打印如下:
***************************
APPLICATION FAILED TO START
***************************
Description:
A component required a bean of type '' that could not be found.
Action:
Consider defining a bean of type '' in your configuration.
出现这种问题,目前收集到了两种解决方式:
1.在Mapper接口上使用@Mapper注解,但是这种方法有个弊端,就是当我们有很多mapper的时候,每一个接口上都需要添加@Mapper注解,这样显得很是繁琐。那么第二种方法就来了。
@Mapper
public interface UserMapper {
User getUserByName(String name);
}
2.在(启动类)上添加@MaperScan注解来解决,来扫描某个包下的所有Mapper接口。
@SpringBootApplication
@MapperScan(value = "")
public class DemoApplication {
public static void main(String[] args) {
(, args);
}
}
这样的话,下的所有mapper都可以被扫描到。没有@Mapper那么繁琐。
广大的猿辈门有什么好的解决方法可以告诉我卅!!!