In our application we are experiencing performance problems with component-scan. It is quite slow and its performance does not depend on number of classes in the scanned package.
Each line like this in our sping configuration file:
<context:component-scan base-package="foo.bar" />
adds 2 minutes to startup time of our application. Number of classes in the scanned package does not matter - we are experiencing the same delay both for packages with 10 and 1k classes.
Why performance of component-scan does not depend on the size of the scanned package?
We are using mixed approach for creating spring beans - we use both xml definitions and component scan. Can this be the reason for such a behavior?
What Spring does is to go through all the classes in the packages you give in the component-scan and if the class has Component, Repository or Service it registers a bean in the context. So the number of classes matters. You have to scan only packages witch contains annotated classes(scanning non annotated classes will take time too). Also you can use only one component scan tag and list all the packages. Using both xml and component scan should not be a problem as long as they don't duplicate.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With