About SpringBoot startup error: Consider defining a bean of type'xx.xx.*Service' in your configuration
1. Question details
***************************
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. Problem interpretation
Prompt intent: Consider defining a type of'com.cloud.servicewebsite.appfile.AppFiles service' in your configuration.
That is to say, a certain Service bean that you handed over to Spring to manage is not scanned, resulting in failure to instantiate.
The solution is: specify the scan package path to load .
3. Solution
Add the @ComponentScan
following code in the startup class of SpringBoot :
@ComponentScan(basePackages = {
"指定的包路径"})
Examples are demonstrated as follows: