四、Spring Boot供给的优雅封闭功能
我们一般采取如下的方法,启动一个Spring boot应用:
- public static void main(String[] args) throws Exception {
- SpringApplication.run(SampleController.class, args);
- }
SpringApplication.run()代码如下,会调用到refreshContext(context)办法:
- public ConfigurableApplicationContext run(String... args) {
- StopWatch stopWatch = new StopWatch();
- stopWatch.start();
- ConfigurableApplicationContext context = null;
- FailureAnalyzers analyzers = null;
- configureHeadlessProperty();
- SpringApplicationRunListeners listeners = getRunListeners(args);
- listeners.started();
- try {
- ApplicationArguments applicationArguments = new DefaultApplicationArguments(
- args);
- ConfigurableEnvironment environment = prepareEnvironment(listeners,
- applicationArguments);
- Banner printedBanner = printBanner(environment);
- context = createApplicationContext();
- analyzers = new FailureAnalyzers(context);
- prepareContext(context, environment, listeners, applicationArguments,
- printedBanner);
- refreshContext(context);
- afterRefresh(context, applicationArguments);
- listeners.finished(context, null);
- stopWatch.stop();
- if (this.logStartupInfo) {
- new StartupInfoLogger(this.mainApplicationClass)
- .logStarted(getApplicationLog(), stopWatch);
- }
- return context;
- }
- catch (Throwable ex) {
- handleRunFailure(context, listeners, analyzers, ex);
- throw new IllegalStateException(ex);
- }
- }
推荐阅读
买与卖2017年数据中间市场处于持续变更的状况。客户加快向云端迁徙带来的压力,再加上部件缺乏,使得数据中间>>>详细阅读
本文标题:常见Java应用如何优雅关闭
地址:http://www.17bianji.com/lsqh/39920.html
1/2 1

网友点评
精彩导读
科技快报
品牌展示