title: Spring Event for all Contexts being initialized
body: <p>A similar question has been answered...</p>
  
  <p>Here: <a href="https://stackoverflow.com/questions/23054452/listener-for-server-starup-and-all-spring-bean-loaded-completely">Listener for server starup and all spring bean loaded completely</a></p>
  
  <p>Here: <a href="https://stackoverflow.com/questions/8686507/how-to-add-a-hook-to-the-application-context-initialization-event">How to add a hook to the application context initialization event?</a></p>
  
  <p>and several other places.</p>
  
  <p>In my primary application, when the Root Spring context initializes it will trigger three child contexts to initialize.  When listening for an event to fire (based on the ContextRefreshedEvent), this results in four total events.  This does not give the consumer of these events accurate information regarding the overall state of the application's Spring context.</p>
  
  <p>Unfortunately I don't have the ability to change the primary application.  The code that I'm wrestling with now is packaged as a jar and loaded into the primary application using a plugin architecture.  I am able to hook into the application's Spring context without issue, and I can successfully receive ContextRefreshEvent triggers.</p>
  
  <p>What I'm looking for is a way to understand if all Spring application contexts in the primary application have completed.  One thing I tried was to manually keep track of the starting and completing of the application context (using a map) so that I could tell when all known application contexts were finished initializing.  This didn't work for me, as I found that the ContextStartedEvent didn't trigger during Spring's refresh operation.</p>
  
  <p>Additional things that could work for me would be knowing how many application contexts exist or how many beans there are that need to be loaded.  That way I could keep track of them as they finished and ultimately know that all application contexts are complete.</p>
  
  <p>Any ideas would be appreciated.</p>
  
  <p><strong>EDIT</strong></p>
  
  <p>In an attempt to ask as pointed a question as possible, I made this question too prescriptive in terms of the implementation.  Here is the actual problem that I was trying to solve (in the form of a question):</p>
  
  <p>How might a plugin, packaged as a jar inside of a webapp, tell when the context of the webapp has been deployed successfully in Tomcat?</p>
  
  <p>Through testing, I thought it was fairly safe to assert that the initialization of the Spring context was synonymous with the deploy phase of the application through Tomcat.  This may be false, but it lined up well enough.</p>
  
  <p>Broadening the scope of the fix from exclusively using Spring, I was able to come up with a solution to the problem.  I will post that as a separate answer.</p>