gpt4 book ai didi

java - IllegalStateException : org. springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@xxxxxxxx 已关闭

转载 作者:行者123 更新时间:2023-11-30 05:32:55 28 4
gpt4 key购买 nike

使用执行器重新启动 Spring Boot 应用程序后,我们无法启动该应用程序。

我们有 Spring Boot 应用程序,我们想要实现一个可以使用执行器重新启动应用程序的功能。应用程序能够运行,但是当我们调用 restart() 时,它不会启动并抛出异常:

"Caused by: java.lang.IllegalStateException: org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@1b84f475 has been closed already"

    //Controller Class
@PostMapping("/restartApp")
public void restartUsingActuator() {
restartService.restartApp();
}


//Service Class
@Autowired private RestartEndpoint restartEndpoint;

public void restartApp() {
System.out.println("in restartApp");

ConfigurableApplicationContext ctx = restartEndpoint.restart();
ctx.refresh();

}

期望运行该应用程序。

最佳答案

如上所述here :

it’s important to recreate the context in a separate non-daemon thread — this way we prevent the JVM shutdown, triggered by the close method, from closing our application. Otherwise, our application would stop

您看到的错误意味着 Spring 应用程序已停止,因此没有注入(inject)的 RestartEndpoint 服务可用于重新启动应用程序。

那篇文章应该有帮助。

关于java - IllegalStateException : org. springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@xxxxxxxx 已关闭,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57185023/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com