以编程方式重启Spring Boot应用程序 [英] Programmatically restart Spring Boot application
问题描述
我正在使用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屋!