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.