In my Spring Boot application I need to wait until the (default Tomcat) web server is fully initialized and ready to take traffic before I send messages to other applications telling them to send HTTP requests to me (specifically a monitoring system that hits my /health
).
I've tried putting the logic that sends messages to other applications in a ApplicationListener<ContextRefreshedEvent>
but it's still too early. The other applications try to make requests to me and fail. Right now I've put a delay in the onApplicationEvent
and that works but it's hacky and racy.
I've also tried adding a ServletContextInitializer
but that fired even earlier.
I'm assuming that I'll need to use a Tomcat API but I wanted to see if there was something in the Boot API for this.