Question

Is there anyway to configure Spring to cache component-scan / autowiring information to improve startup times from one start to another? I'm investigating using GAE for a Spring app for the first time, and according to the GAE docs they recommend pretty much disabling all the practical features that Spring offers to make development faster. Ex: component-scan, autowiring, using lazy-init beans, etc. Basically everything that takes the container longer to setup.

Although I understand the principal behind all these suggestions, I find that it is almost taking a step backwards in the development process. What would make it very interesting / useful is if there was a way for Spring to generate a cache file of sorts that it could reference for future startups to avoid having to do the full component scan/etc every time.

Does anything like this exist?

Was it helpful?

Solution

That functionality currently does not exist, the major problem with it would be where to store that information between startups, access would have to granted to a directory in the file system, etc.

The usual way to speed up startup is to do component scan of subpackages that contain only the set of classes that are scannable, or avoid scanning altogether and use XML instead.

Also if there is an ORM framework like Hibernate involved, i helps to turn off schema validation. Using lazy initialized beans also reduces the startup time, there is currently no alternative to these measures to reduce boot time.

OTHER TIPS

HK2 has done a LOT of work in the area of performance at startup. For example, if you use the hk2-inhabitant-generator at build time it can add a file into your jar (under META-INF/hk2-locator/default) that gives a list of services that can be injected and/or loaded with HK2. The benefit of this is that at startup the services can be "available" in HK2 without ever having classloaded any of the services. This in turn can lead to a huge boost in startup time (it is how we got extremely fast startup times in products like GlassFish). You can combine this with the hk2 run-level service in order to bring your system up in a structured fashion. Also, if you are using Spring there is a Spring-HK2 bridge that will allow you to keep most of your services in Spring if you would like that. But obviously an service that remains in Spring will not benefit from the lazy classloading that is available in HK2.

You can also bypass the need to minimize starting up/wiring time by replacing what you need while your server is running, with a tool like JRebel.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top