Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Spring - complete shutdown of web application

Tags:

java

spring

I have a web application which I'm trying to shut down by executing the close() method on the context:

((ConfigurableApplicationContext) appContext).close();

After executing this the application appears to be continuing running, health page produces the following exception:

org.springframework.web.util.NestedServletException: Request processing failed; nested exception is java.lang.IllegalStateException: BeanFactory not initialized or already closed - call 'refresh' before accessing beans via the ApplicationContext
    at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:978)

Is there a way to shudown the whole thing via Spring or should I resort to System.exit()?

Any help would be kindly appreciated!

like image 414
alexs333 Avatar asked Nov 10 '22 17:11

alexs333


1 Answers

PLease have a look at these questions. They are on the same line as yours: How to manage Tomcat via Java, Start / stop a web application from itself?

As @chrylis suggested, I think the easiest way of shutting down the server(if it's not running in embedded mode) is to use Runtime class.

like image 103
geekprogrammer Avatar answered Nov 15 '22 08:11

geekprogrammer