关于SpringBoot启动报错Consider defining a bean of type 'xx.xx.*Service' in your configuration
1、问题详情
***************************
APPLICATION FAILED TO START
***************************
Description:
Field appFileService in com.cloud.appfile.fileserver.UploadFileController required a bean of type 'com.cloud.service.appfile.AppFileService' that could not be found.
The injection point has the following annotations:
- @org.springframework.beans.factory.annotation.Autowired(required=true)
Action:
Consider defining a bean of type 'com.cloud.service.appfile.AppFileService' in your configuration.
2、问题解读
提示原意:考虑定义一个类型为’com.cloud.service网站.appfile.AppFiles服务’在你的配置中。
也就是说你交给Spring管理的某个Service bean没有扫描到,导致无法进行实例化。
解决思路是:指定扫描包路径进行加载。
3、解决方法
在SpringBoot的启动类中加入@ComponentScan
,格式如下所示的代码:
@ComponentScan(basePackages = {"指定的包路径"})
实例演示如下: