@ComponentScan doesn't work in Spring boot AutoConfiguration class?

you have to use the compentscan annotation into the main class. Here a sample code:

@SpringBootApplication
@ComponentScan("com.foo.project")
public class MainApplication extends SpringBootServletInitializer {

    @Override
    protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
        return application.sources(MainApplication.class);
    }

    public static void main(String[] args) {
        new MainApplication().configure(new SpringApplicationBuilder(MainApplication.class)).run(args);
    }
}

Cheers


Automatic everything requires the Application class (annotated with @SpringBootApplication) to be in a "higher" package than the components you want to scan.

Use:

package com.example.foo;

for your application and put components in a package like:

package com.example.foo.entities;

See also https://docs.spring.io/spring-boot/docs/current/reference/html/using-boot-using-springbootapplication-annotation.html