1

I have initialization code that I want to run after Spring has refreshed all ApplicationContexts.

Right now I have an instance of ApplicationListener<ContextRefreshedEvent> that listens for when my contexts are done, but it gets called for every context in my application.

How can I listen for the very last one?

I've tried to listen for the root using event.getApplicationContext().getParent() == null but this is not the last context to load.

Roy Truelove
  • 22,016
  • 18
  • 111
  • 153

1 Answers1

0

UPDATE This doesn't work; keeping the answer here for posterity.

I'm using the Spring scheduler for this; it seems to be the only thing that starts after Spring is really and truly finished loading. (see here for reference):

<task:scheduled-tasks scheduler="someScheduler">
    <task:scheduled ref="foo" method="bar"
        initial-delay="1" fixed-rate="#{ T(java.lang.Long).MAX_VALUE }" />
</task:scheduled-tasks>
Community
  • 1
  • 1
Roy Truelove
  • 22,016
  • 18
  • 111
  • 153