This week's book giveaway is in the Mac OS forum. We're giving away four copies of a choice of "Take Control of Upgrading to Yosemite" or "Take Control of Automating Your Mac" and have Joe Kissell on-line! See this thread for details.
One part of my application is listening to a topic for refreshing my cache.
But suppose the server which is publishing the message is down. I still want my application to come up.
I tried to set lazy-int = true and then after the context is loaded tried to do context.getBean("testUpdateListener") thinking it will initialize the bean and it will start listening.
But it does not work. The listener does not start listening.
First off, for listeners. Why aren't you using the jms namespace. So your config is as simple as
lazy-init has nothing to do with starting or shutting down a listener container. It is only about when Spring instantiates an object. And for me, I would never ever use lazy-init in my configuration. I want everything created up front.
It is better for memory, heap, also telling me about errors earlier which reduces my costs to find bugs.
Even with lazy init you would still have this problem.
If you don't have the listener, how will your application still be able to run. What if it still isn't up when a user needs it?
You could do some tricks, like parent child application contexts. Where you put yours listener into its own application context. When you create it in code, wrap it in a try-catch. Maybe even run that code in a separate thread that keeps running every 10 minutes until the listener is up, then after that application context is created stop running that job. And pass the other application context to the constructor to be the parent. Now it might need to be reversed because child application contexts can see beans in the parent, but not the other way around.
There might be another solution that I am not aware of.