I have a Spring Boot application. I've added a lot of dependencies (unfortunately, looks I need all of them) and the startup time went up quite a lot. Just doing a SpringApplication.run(source, args)
takes 10 seconds.
While that might not be much compared to what are "used" to, I'm unhappy that it takes that much, mostly because it breaks the development flow. The application itself is rather small at this point, so I assume most of the time is related to the added dependencies, not the app classes themselves.
I assume the issue is classpath scanning, but I am not sure how to:
- Confirm that is the issue (i.e. how to "debug" Spring Boot)
- If it really is the cause, how can I limit it, so it gets faster? For example, if I know that some dependency or package does not contain anything that Spring should be scanning, is there a way to limit that?
I assume that enhancing Spring to have parallel bean initialization during startup would speed up things, but that enhancement request has been open since 2011, without any progress. I see some other efforts in Spring Boot itself, such as Investigate Tomcat JarScanning speed improvements, but that is Tomcat specific and has been abandoned.
This article:
although aimed at integration tests, suggests using lazy-init=true
, however I do not know how to apply this to all beans in Spring Boot using Java configuration - any pointers here?
Any (other) suggestions would be welcome.
@ComponentScan
those are scanned as well. Another thing is to make sure you haven't enabled debug or trace logging as generally logging is slow, very slow. – Malmsey