I have a spring based webapp that persists data with Hibernate. The default web page that comes up when the service is deployed immediately makes an ajax request for the data. So if the data doesn’t already exist, it needs to be fetched and persisted. I want to make sure that when I deploy the service, before spring is up and tomcat is serving out my web pages that I can execute code to fetch and persist my data.
I thought a regular context listener might do the trick, but I don’t know if there’s any guarantee that it will finish before everything else is initialized. Is there something in Spring that can do this? Or will a context listener do the trick?
You can use application events (context events) of spring, refer to doc for
ContextStartedEvent