@Autowired 和 啟動(dòng)類的關(guān)系
這是我之前的文件結(jié)構(gòu):
這時(shí)候在 UserController 的構(gòu)造函數(shù) (有@Autowired 注解)中會(huì)報(bào)錯(cuò)(Could not autowire. No beans of 'UserRepository' type found.)并且無(wú)法正常啟動(dòng)。
然后把 啟動(dòng)類 LearningSpringbootDemoApplication 放到runner 中后就沒(méi)有問(wèn)題了。
這是哪方面的原因呢?
2022-06-13
引用的porm估計(jì)路徑不對(duì)
2021-07-21
看下你的UserRepository類 有沒(méi)有添加@Repository 注解