Announcement Announcement Module
Collapse
No announcement yet.
How to find if all the beans are initialized? Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • How to find if all the beans are initialized?

    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?

  • #2
    You can try to use the depends-on attribute on the service bean which will say that it depends on bean A and bean B.
    e.g.
    <bean id="serviceBean" class="ServiceBean" depends-on="beanA,beanB"/>

    <bean id="beanA" class="BeanA"/>
    <bean id="beanB" class="BeanB"/>

    or alternatively you can also try

    <bean id="serviceBean" class="ServiceBean"/>

    <bean id="beanA" class="BeanA" depends-on="beanB"/>
    <bean id="beanB" class="BeanB"/>

    Comment


    • #3
      Can you share your configuration files, normally Spring parses the application context & figures the dependencies, which it then uses to determine sequence for initialization of beans

      Comment


      • #4
        good info it is



        -----------------------------------------------
        where to buy oil painting
        Last edited by kinglee; Sep 7th, 2012, 05:30 AM.

        Comment

        Working...
        X