Introduction
In this post, we will see multiple ways to use @PackageScan annotation.
Multiple Ways of Using @PackageScan
- Provide Single package
@ComponentScan("com.mypackage1")- 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 = {
@ComponentScan("com.mypackage1"),
@ComponentScan("com.mypackage2")
})See another post, where we write on Fixing Autowire Bean Not Found
$ subscribe --weekly
One deep dive a week, in your inbox
System design, AI engineering, trading systems and interview prep. Tested code, real numbers. Free, and you can unsubscribe any time.
or read it on gyanbyte.substack.com












