Springboot程序以控制台程序方式运行

 1 public class Application {
 2     public static void main(String[] args) {
 3         ConfigurableApplicationContext ctx = SpringApplication.run(Application.class);
 4         
 5         HelloWorldService service = ctx.getBean(HelloWorldService.class);
 6         service.doTask();
 7         
 8         // 第一种方式
 9         //ctx.close();
10         
11         // 第二种方式
12         int code = SpringApplication.exit(ctx,(ExitCodeGenerator)() -> 0);
13         System.exit(code)
14     }
15 }

 

posted @ 2024-05-09 20:27  凤凰涅磐欲重生  阅读(26)  评论(0编辑  收藏  举报