启动类中加入如下代码 (exitApplication方法)
public static void main(String[] args) {
ConfigurableApplicationContext run = null;
try {
run = SpringApplication.run(LicenseApplication.class, args);
} catch (Exception e) {
if(null != run){
exitApplication(run);
}
}
}
//退出容器的代码
public static void exitApplication(ConfigurableApplicationContext context) {
int exitCode = SpringApplication.exit(context, (ExitCodeGenerator) () -> 0);
System.exit(exitCode);
}