我试图以编程方式重新启动Spring应用程序,而无需用户干预.
基本上,我有一个页面,允许切换应用程序的模式(实际上意味着切换当前活动的配置文件),据我所知,我必须重新启动上下文.
Currently my code is very simple, it's just for the restarting bit (this is Kotlin by the way):
context.close()
application.setEnvironment(context.environment)
ClassUtils.overrideThreadContextClassLoader(application.javaClass.classLoader)
context = application.run(*argsArray)
然而,当我执行context.close()
的时候,JVM立即就存在了.我也try 了context.refresh()
,但这似乎简单地杀死了Tomcat/Jetty(两者都try 过,以防是Tomcat问题),然后什么也没有发生.
I have also seen Programmatically restart Spring Boot application but nothing seems to work for me from those answers. Furthermore, I looked into Spring Actuator which supposedly has the /restart
endpoint, but that doesn't seem to be there anymore?