@ComponentScan
will give you a list of all the classes with the @Component
annotation in a package (or @Service
/@Repository
). To do this I imagine they use reflection to enumerate all the classes in a package and find the ones with that annotation.
However according to other StackOverflow answers you can not reliably enumerate all the classes in a package due to how the ClassLoader
works. So how does @ComponentScan
seemingly manage to accomplish this?
findCandidateComponents
acceptingbasePackage
as an input argument and thenResourcePatternResolver
instance reads all the classpath files with.class
suffix. Hope this helps! – Uniformed