@Autowired 和 啟動類的關系
這是我之前的文件結構:
這時候在 UserController 的構造函數 (有@Autowired 注解)中會報錯(Could not autowire. No beans of 'UserRepository' type found.)并且無法正常啟動。
然后把 啟動類 LearningSpringbootDemoApplication 放到runner 中后就沒有問題了。
這是哪方面的原因呢?
這是我之前的文件結構:
這時候在 UserController 的構造函數 (有@Autowired 注解)中會報錯(Could not autowire. No beans of 'UserRepository' type found.)并且無法正常啟動。
然后把 啟動類 LearningSpringbootDemoApplication 放到runner 中后就沒有問題了。
這是哪方面的原因呢?
舉報
2022-06-13
引用的porm估計路徑不對
2021-07-21
看下你的UserRepository類 有沒有添加@Repository 注解