Announcement Announcement Module
Collapse
No announcement yet.
How to get state of DI? Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • 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
    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.

    Comment


    • #3
      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.

      Comment


      • #4
        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.

        Comment

        Working...
        X