Results 1 to 4 of 4

Thread: How to find if all the beans are initialized?

  1. #1
    Join Date
    Aug 2012
    Posts
    1

    Default 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. #2
    Join Date
    Jun 2011
    Posts
    5

    Default

    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"/>

  3. #3
    Join Date
    May 2011
    Location
    New Delhi, India
    Posts
    157

    Default

    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

  4. #4

    Default

    good info it is



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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •