Spring - Learn Multiple Ways to use PackageScan Annotation

January 14, 2022


In this post, we will see multiple ways to use @PackageScan annotation.

Multiple Ways of Using @PackageScan

  • Provide Single package
  • Provide Multiple Packages by String[] array
@ComponentScan({"com.mypackage1", "com.mypackage2"})
  • By Specifying Classes
@ComponentScan(basePackageClasses = {MyClass1.class, MyClass2.class})

This way is type-safe.

  • By Using basePackages attribute
@ComponentScan(basePackages={"com.mypackage1", "com.mypackage2"})
  • Nested Usage of ComponentScan
@ComponentScans(value = { 

See another post, where we write on Fixing Autowire Bean Not Found

Similar Posts

Latest Posts