Component Scanning[base Package]

  • Spring Container will not read all classes defined in workspace/project by default.

  • It will read classes only from one common package name ie also called as BasePackage given using @ComponentScan Annotation.

  • basePackage : It is a package name, that will read classes from current package and sub package only.

  • In Spring we used to provide base Package using @ComponentScan (basePackage ="in.example.sunil")

  • In Spring Boot (Starter class)/Main class package name taken default as basePackage. Our class must be in same package or its subpackage.

  • In simple you class package = starter class package + subpackage

@ComponentScan(basePackages = { "","in.example.sunil","in.example.execute",})

public class SpringBoot2RunnerComponentScanApplication {
             public static void main(String[] args) {
           , args);