Perform specific operations when the spring boot container is loaded (recommended)
In some cases, we need to perform some operations after the spring boot container is started and loaded. At this time, we can implement the applicationlistener < e extensions applicationevent > interface and specify the corresponding events to perform the operations, such as starting some custom daemon threads
Applicationcontextevent is the base class of events raised by ApplicationContext. It has several implementation classes:
Contextrefreshedevent: this event is triggered when the ApplicationContext container is initialized or refreshed, Execute a contextstartedevent: this event is triggered when the ApplicationContext container is started by using the start() method of the configurableapplicationcontext interface. Contextclosedevevent: when using the close() method of the configurableapplicationcontext interface Method triggers this event when the ApplicationContext container is closed. Contextstopedevent: this event is triggered when the ApplicationContext container is stopped using the stop() method of the configurableapplicationcontext interface
Code example
summary
The above is what Xiaobian introduced to you. The spring boot container performs specific operations when loading. I hope it will be helpful to you. If you have any questions, please leave me a message, and Xiaobian will reply to you in time. Thank you very much for your support for the programming tips website!