简体   繁体   English

Spring - 完全关闭Web应用程序

[英]Spring - complete shutdown of web application

I have a web application which I'm trying to shut down by executing the close() method on the context: 我有一个Web应用程序,我试图通过在上下文上执行close()方法来关闭:

((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() ? 有没有办法通过Spring来扼杀整个事情,还是应该诉诸System.exit()

Any help would be kindly appreciated! 任何帮助将不胜感激!

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? 它们与您的系列相同: 如何通过Java管理Tomcat从自身启动/停止Web应用程序?

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. 正如@chrylis建议的那样,我认为关闭服务器的最简单方法是(如果它不是以嵌入模式运行)是使用Runtime类。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM