You can use @ComponentScan in order to configure more complex package scanning. There is also @ComponentScans that act as a container annotation that aggregates several @ComponentScan annotations.
Basic code examples
@ComponentScan
public class DemoAutoConfiguration {
}
@ComponentScans({@ComponentScan("com.example1"), @ComponentScan("com.example2")})
public class DemoAutoConfiguration {
}
Stating @ComponentScan with no configuration acts like @SpringBootApplication and scans all packages under the class annotated with this annotation.
In this example I will state some of the useful attributes of @ComponentScan:
@Component, @Repository, @Service, or @Controller automatically.There are many more attributes but those are the most commonly used in order to customize package scanning.