关于SpringBoot无法找到Service层的说明

SpringBoot的报错信息为:
Description:
A component required a bean of type ‘*****.service’ that could not be found.

Action:
Consider defining a bean of type ‘*****.service’ in your configuration.

Process finished with exit code 1

出现这个问题的根本原因就是spring没找到你的Service注解

1、你的service层没有写在springboot启动类的同级或者下级目录
像这样:在这里插入图片描述
这样spring是扫描不到service文件的

2、你的@Service注解写在了接口上在这里插入图片描述
这种情况下,这个@Service注解也是不会生效的,也会产生上述的错误

我们只能将@Service注解写在Service的实现类impl那个类上,才能使注解正常生效
在这里插入图片描述

Logo

为开发者提供学习成长、分享交流、生态实践、资源工具等服务,帮助开发者快速成长。

更多推荐