Results 1 to 4 of 4

Thread: How to get state of DI?

Hybrid View

  1. #1
    Join Date
    Mar 2006
    Location
    Germany, Karlsruhe
    Posts
    157

    Default How to get state of DI?

    Hi,

    I want to know if bean initialization is done and everything is ok (no errors).
    How can I programatically do that?

    Best regards,

    Ingo

  2. #2
    Join Date
    Sep 2012
    Location
    Czech Republic
    Posts
    39

    Default

    Can you be more specific? If there is an error during Spring context creation, an exception is thrown. By @Required annotation on a bean, you can check that a dependency is injected. @Autowired properties are @Required by default.
    You can load a bean by applicationContext.getBean(..) and then perform any check you want on a class instance.

  3. #3
    Join Date
    Mar 2006
    Location
    Germany, Karlsruhe
    Posts
    157

    Default

    Sorry, I wasn't clear enough.
    I want to know if all defined beans have bean correctly initialized (= dependency injection).

    Why I am doing this?
    I want to write a "health" servlet that returns a HTTP 200 message if all OSGi bundles with Spring DI has been initialized without an error.

  4. #4
    Join Date
    Mar 2006
    Location
    Germany, Karlsruhe
    Posts
    157

    Default

    I found a solution by implementing an OsgiBundleApplicationContextListener.

    OsgiBundleContextFailedEvent: Signals an bean configuration error in a bundle. That's the most important part.

    My application is huge, that's why it takes a while to init al beans. That's why I added an additional check:

    BootstrappingDependencyEvent + OsgiBundleContextRefreshedEvent: I save all symbolic names of bootstrapping and refresh events in a set. I remove all refresh events form the bootstrapping set and if the result is empty, then all contexts of bundles have been processed.

Posting Permissions

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