关闭a
SpringApplication基本上意味着关闭基础
ApplicationContext。该
SpringApplication#run(String...)方法为你提供了
ApplicationContext一个
ConfigurableApplicationContext。你可以close()自己动手做。
例如,
@SpringBootApplicationpublic class Example { public static void main(String[] args) { ConfigurableApplicationContext ctx = SpringApplication.run(Example.class, args); // ...determine it's time to shut down... ctx.close(); }}
另外,你可以使用
static SpringApplication.exit(ApplicationContext, ExitCodeGenerator...)帮助程序方法来帮助你。例如,
@SpringBootApplicationpublic class Example { public static void main(String[] args) { ConfigurableApplicationContext ctx = SpringApplication.run(Example.class, args); // ...determine it's time to stop... int exitCode = SpringApplication.exit(ctx, new ExitCodeGenerator() { @Override public int getExitCode() { // no errors return 0; } }); // or shortened to // int exitCode = SpringApplication.exit(ctx, () -> 0); System.exit(exitCode); }}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)