I want to scan the other files that are not in src.main.java.
But the @ComponentScan annotation is scanning the packages only in the src.main.java folder.
I think you need to add folders manually into your java build path before adding them into component scan. If you are using Eclipse, there is a way to add them in build path by right clicking on project -> properties -> java build path -> source. You need to add the path to src/<path to your additional source>
here and enable it so that it is recognized as a source folder. Then you need to use @ComponentScan to scan for the relevant packages. Key thing here is to get your relevant code into the classpath.
One scenario i can think of where you would potentially need such kind of changes would be having some generated sources under target/generated-sources
and you need to use those stubs or beans to develop your code.