Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

contextstoppedevent vs contextclosedevent in spring?

Can any one please explain me what is the difference between the contextstoppedevent vs contextclosedevent in spring .

I think they are same like ,

ConfigurableApplicationContext sss = (ConfigurableApplicationContext) ((ApplicationContextEvent) event).getApplicationContext();
sss.stop();
sss.close();

May I know where I have to use and when I have to use it ?

like image 477
Human Being Avatar asked Nov 15 '13 11:11

Human Being


1 Answers

First of all, in the vast majority of cases, it's not you who has to explicitly call the stop() and close() methods. Usually, they will be called by the framework and you will listen for the associated events.

You can find here a good comparison of events related to Spring lifecycle. Essentially, closing event occurs chronologically after any other stop events. A stopped context can be restarted, but a closed one cannot be reopened.

like image 139
Andrei Nicusan Avatar answered Sep 24 '22 12:09

Andrei Nicusan