I may be hitting on a Threading issue with Spring I hope I get a way to circumvent. We have a Spring bean (say A) that we inject another dependency (say B) into. A set of services use bean A but I am seeing a behaviour that while the service comes up and tries to use bean A, the bean B is not available right away. They are not lazy loaded and if we put a sleep for a few ms the bean B gets injected. The core of the problem is that the services are coming up before Spring is fully initialized and the challenge is the service does not have any reference to Spring's application context.
I tried attaching an ApplicationListener for a ContextStartedEvent and I see the same behaviour that this event is dispatched while not all beans are completely initialized though none are lazily initialized.
Is there a way to ensure beans are guaranteed to be initialized and all its dependencies before the Services begin using them?