Java springboot Service中无法通过@Autowired导入Dao包

报错:Could not autowire. No beans of ‘UserMapper’ type found

原因是Dao为interface 无法通过@Bean加入到容器,也就无法通过@Autowired自动注入
解决方法:Dao上加上@Repository 它用于将数据访问层 (DAO 层 ) 的类标识为 Spring Bean,注释后即可使用@Autowired进行注入

对了 还要再Application类加上@MapperScan(“mapper包的位置例如:com.example.mybatistest.mapper”)

原文地址:https://www.cnblogs.com/niuniu0108/p/13634098.html