An error is reported when springboot starts: error creating bean with name ‘XXXX’

Error creating bean with name ‘XXXX’

The complete errors are as follows: Cause Analysis:

The complete error report is as follows:

 Exception encountered during context initialization - cancelling refresh attempt: 
 org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 
 'testHelloController': Unsatisfied dependency expressed through field 'testHelloService'; nested exception is 
 org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 
 'com.jun.service.test.TestHelloService' available: expected at least 1 bean which qualifies as autowire 
 candidate. Dependency annotations: 
 {@org.springframework.beans.factory.annotation.Autowired(required=true)}

Cause analysis:

Because I’m a beginner of springboot, I just want to let the project run first to see the effect. If it takes half a day to build the project structure completely, I will report such a mistake as soon as I start it. The reason is very clear, that is, I can’t find the testhelloservice object template to inject it when I start it, and then I look at the @ service annotation in the service layer. It’s very smart When spring boot is started, it does not scan the service layer. After looking at the data, if so, you can directly type a annotation @ componentscan in the application of spring boot startup class to solve this problem:
the following is the code before error reporting:

package com.jun.web.test;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
public class Application {
    public static void main(String[] args) {
        SpringApplication.run(Application.class,args);
    }
}

Code after error reporting:

package com.jun.web.test;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.ComponentScan;

**@ComponentScan(basePackages = {"com.jun.core.*","com.jun.service.*","com.jun.web.*"})**
@SpringBootApplication
public class Application {
    public static void main(String[] args) {
        SpringApplication.run(Application.class,args);
    }
}

Read More: