spring boot 启动的时候required a bean of type 'XXX' that could not be
- 学习笔录-spring boot
- 时间:2018-07-16 22:55
- 7848人已阅读
简介
Field mapper in com.demo.service.impl.UserServiceImpl required a bean of type 'com.kaigejava.kgblog.dao.UserDao' that could not be found.
🔔🔔🔔好消息!好消息!🔔🔔🔔
有需要的朋友👉:联系凯哥
Description:
Field mapper in com.kaigejava.kgblog,service.impl.UserServiceImpl required a bean of type 'com.kaigejava.kgblog.dao.UserDao' that could not be found.
Action:
Consider defining a bean of type 'com.kaigejava.kgblog.dao.UserDao' in your configuration.
SpringBoot启动失败,告诉我Bean配置失败,楼主看了看 该用的注解都用上了 这是咋的回事嘞?
先看错误的:
//@Component @Repository public interface UserMapper { int insert(UserDomain record); List<UserDomain> selectUsers(); }
这两个注解都是用了,为什么还会报错呢?
查询:
解决方案一:
后来在网上看到网友说要用@Mapper注解,这才把问题解决了 至于具体原因,楼主还需要好好看看文档再来解释。
于是修改:
@Mapper public interface UserDao { int insert(UserDomain record); List<UserDomain> selectUsers(); }
重新启动,启动正常。访问ok.
解决方案二:
先看失败之前的Application(启动类):
@SpringBootApplication public class KgblogApplication { public static void main(String[] args) { SpringApplication.run(KgblogApplication.class, args); } }
根据错误提示,没有UserDao这个bean.那么我们就在启动类上将该报扫描进去:
//@SpringBootApplication @SpringBootApplication @MapperScan(value = {"com.kaigejava.kgblog.dao"}) public class KgblogApplication { public static void main(String[] args) { SpringApplication.run(KgblogApplication.class, args); } }
解决方案三: