We use Spring MVC annotations.
I have a StartUpServlet as well. My requirement is to load this servlet after the FilterDispatcher servlet is initialized.
Basically, we would like to initialize the Google Guava cache and load the cache with the data from the table.
I can have a static block and load the data. But the problem is the class where we do the cache initialization and cache loading might be garbage collected if we never access it for long time.
So, though of having the cache loading class instance refernece inside a servlet so that it will never be garbage collected. But the servlet gets loaded before the FrameworkServlet dispatcher initialized and Dependency injections are working.
This idea above relies on if the root application context Spring container will stay alive during the entire life of the web application, and that the Spring container will never garbage-collect the Spring singleton bean instance in it, while the Spring container is alive.
The way you are doing this is very anti-Spring. In Spring based apps, you don't need to have Singletons because you it;s much easier to create single instances of classes. Why aren't you simply declaring codesCache and cityCache as Spring beans? You can easily implement factory beans, one for each that can initialize the 2 caches. You can then autowire the 2 caches wherever you need them. Also, this ensures that your initialization routines will be called by spring at the correct point of the lifecycle. Also, you can use lifecycle annotations on your classes to do other init and cleanup
It seems to me like you are trying to jam a ServiceLocator pattern onto a framework that already has Dependency Injection. You have DI.. use DI.
What could go wrong in a swell place like "The Evil Eye"? Or with this tiny ad?
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop