Spring boot无法注入service

Spring boot无法注入service,第1张

在写作业时发现项目运行显示

Description: A component required a bean of type 'com.example.demo.service.impl.

UserServiceimpl' that could not be found.

Action: Consider defining a bean of type 'com.example.demo.service.impl.UserServiceimpl' in your configuration.

最后总结以下几点报错原因:

1.Service的实体类没注释@Component

2.Application类所在的包没能扫描到Service实体类,如图

因为Application类是从上往下扫当前包和其子包,所以图片放置位置为正确

刚开始学springboot,对于报错一头雾水,只能通过翻译和网页查找报错原因,希望这篇文章能帮到你。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/langs/923970.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-16
下一篇 2022-05-16

发表评论

登录后才能评论

评论列表(0条)

保存