We have a very large spring app, with multiple imported application context files imported by the root (top-level) app context file. I noticed (kinda hard to ignore :-)) that it was taking about 7-10 minutes to start up a POJO test of the functionality. I added TRACE level logging to the spring packages and can see that all of the time is being taken up in spring loading of the app config files...in this statement in my POJO's main method:
ApplicationContext context = new ClassPathXmlApplicationContext("applicationContext-DataFix.xml");
...so I googled around and found out about default-lazy-init="true", which I assumed would speed up the above statement. It didn't, so I googled some more and found this:
...so I coded that as described and added it to my POJO test class's main method, so it now looks like this:
ApplicationContext context = new LazyClassPathXmlApplicationContext("applicationCon text-DataFix.xml");
Sometimes, the above statement runs in about a minute. Other times, it runs in the (unacceptable) 7-10 minutes. I cannot yet get a pattern on why it loads fast sometimes and not others. I've tried all kinds of stuff, including coming out of Eclipse, checking for left-over java processes and so on, trying to imagine what's going on back there.
On the surface, it appears that default-lazy-init (in the <beans> element or programmatically as above) just doesn't work (or works randomly)....but I'm betting I'm just missing something simple about it, since it looks like it's been around for a while.
Also, I'm seeing lots of log statements like this:
org.springframework.beans.factory.support.DefaultL istableBeanFactory - Creating shared instance of singleton bean 'productTransChannelVOValidator'
org.springframework.beans.factory.support.DefaultL istableBeanFactory - Returning cached instance of singleton bean 'updateProductTransRelatedVOValidator'
and I'm wondering why Spring would be creating these bean instances and returning the cached ones, when I just told Spring to not do that?
The bottom line is that I want to configure Spring so that it eagerly inits (and caches) in the deployed environments and lazily inits (and doesn't cache diddly-squat) when I'm step-debugging in Eclipse, since there's no point in eagerly init'ing 500 spring beans when I'm only going to use 5 of them on this particular debug cycle ("debug cycle" meaning I run the driving POJO, step through the code, see a bug, stop the debug run, fix the bug, save the class and run the POJO again).
High-level, I have 2 questions:
1. Does the reason I want to do this make sense? (I'm betting it will coz I'm seeing many other who want to do the same and can't make it happen). Assuming it makes sense....
2. How do I make this happen? i.e. how do I use default-lazy-init (or possibly some other Spring flag/flags) to tell Spring not to instantiate or cache or even reflect on a bean class until I attempt to instantiate the bean at statement execution time?