Field userMapper in com.example.playspring.service.UserService required a bean of type 'com.example.

一、报错信息

Field sysUserMapper in com.example.playspring.service.sysUserService required a bean of type 'com.example.playspring.mapper.sysUserMapper' that could not be found.

二、解决办法:

在主函数类上添加以上注解,可以扫描dao包中的所有接口,替代在每个dao中写@Mapper注解,这样会提高耦合度。

加上@MapperScan注解 后面是mapper接口的类的地址

@MapperScan("com.example.playspring.mapper")

@MapperScan的理解:使用该注解,可以免去每个Mapper类都加上@Mapper

这个注解也可以同时扫描多个包,

如果如果mapper类没有在Spring Boot主程序可以扫描的包或者子包下面,可以使用如下方式进行配置

    @SpringBootApplication  
    @MapperScan({"com.example.*.mapper","org.example.*.mapper"})  
    public class App {  
        public static void main(String[] args) {  
           SpringApplication.run(App.class, args);  
        }  
    }

发布了274 篇原创文章 · 获赞 161 · 访问量 8万+

猜你喜欢

转载自blog.csdn.net/libusi001/article/details/104755557
今日推荐