以编程方式重启Spring Boot应用程序 [英] Programmatically restart Spring Boot application

查看:196
本文介绍了以编程方式重启Spring Boot应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Spring Boot,并且有一个用例,用户可以上载一个文件,这会导致应用程序重新启动(因为在创建多个bean时使用了用户的上载).我知道我可以避免重新启动应用程序,但是此刻-这就是我想要的.

I'm using Spring Boot and I've got a use case where user can upload a file which should cause a restart of application (since user's upload is used during creation of multiple beans). I know I can avoid restarting the application, but at the moment - this is what I want.

我发现

I've found RestartEndpoint in Spring-Cloud project, but it doesn't seem like ApplicationPreparedEvent is fired. Is there any other way I can programmatically restart Spring Boot application?

推荐答案

最简单的方法是调用

The simplest way to do this by calling the refresh() method on the Spring ApplicationContext. This will kill and reload all of your beans, so you should be certain that this occurs only when it is safe for your application to do so.

这篇关于以编程方式重启Spring Boot应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆