1、在pom文件中加入:

<!--平滑升级包 开始 -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<!--平滑升级包 结束 -->

2、在spring配置文件中:

#平滑关闭配置开始
management.endpoint.shutdown.enabled=true
management.endpoints.web.exposure.include=*
#平滑关闭配置结束

3、定制controller

import org.apache.catalina.connector.Connector;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.web.embedded.tomcat.TomcatConnectorCustomizer;
import org.springframework.context.ApplicationListener;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.event.ContextClosedEvent;

import java.util.concurrent.Executor;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

/**
* 定制的 Connector(tomcat处理器)
*
*/
@Configuration
public class CustomShutdown implements TomcatConnectorCustomizer, ApplicationListener<ContextClosedEvent> {

protected final Logger logger = LoggerFactory.getLogger(this.getClass());

private static final int TIMEOUT = 30;

private volatile Connector connector;

@Override
public void onApplicationEvent(ContextClosedEvent event) {
this.connector.pause();
Executor executor = this.connector.getProtocolHandler().getExecutor();
if (executor instanceof ThreadPoolExecutor) {
try {
logger.warn("WEB 应用准备关闭");
ThreadPoolExecutor threadPoolExecutor = (ThreadPoolExecutor) executor;
threadPoolExecutor.shutdown();
if (!threadPoolExecutor.awaitTermination(TIMEOUT, TimeUnit.SECONDS)) {
logger.warn("WEB 应用等待关闭超过最大时长 " + TIMEOUT + " 秒,将进行强制关闭!");
threadPoolExecutor.shutdownNow();
if (!threadPoolExecutor.awaitTermination(TIMEOUT, TimeUnit.SECONDS)) {
logger.error("WEB 应用关闭失败!");
}
}
} catch (InterruptedException ex) {
Thread.currentThread().interrupt();
}
}
}

@Override
public void customize(Connector connector) {
this.connector = connector;
}
}

4、在spring启动类中加入

@Bean
public CustomShutdown customShutdown() {
return new CustomShutdown();
}

/**
* 将定制的添加到tomcat
* @param customShutdown
* @return
*/
@Bean
public ConfigurableServletWebServerFactory webServerFactory(CustomShutdown customShutdown) {
TomcatServletWebServerFactory tomcatServletWebServerFactory = new TomcatServletWebServerFactory();
tomcatServletWebServerFactory.addConnectorCustomizers(customShutdown);
return tomcatServletWebServerFactory;
}

完成

服务器spring boot版本,平滑升级的更多相关文章

  1. Spring Boot 2.0 升级指南

    Spring Boot 2.0 升级指南 前言 Spring Boot已经发布2.0有5个月多,多了很多新特性,一些坑也慢慢被填上,最近有空,就把项目中Spring Boot 版本做了升级,顺便整理下 ...

  2. Spring Boot 1.5升级2.1 主要问题汇总

    我们目前工作的系统是基于Spring Boot 1.5.19.RELEASE.Spring Cloud Edgware.SR3开发的,因为一个新项目开发过程的体验,所以在考虑升级到Spring Boo ...

  3. Spring Cloud与Spring Boot版本匹配关系

    Spring Cloud是什么? “Spring Cloud provides tools for developers to quickly build some of the common pat ...

  4. Nginx1.8.0版本平滑升级新版本1.9.7

    原文:http://www.jb51.net/article/79878.htm 首先查看现在环境nginx的版本为1.8.0 编译的参数只指定了安装路径: 复制代码代码如下: [root@local ...

  5. Jdk和Spring Boot版本选择

    ==========================版本选择的原则:==========================1. 优先选择官方指定的long-term support(LTS)版本, 非L ...

  6. 【Spring Cloud】与Spring Boot版本匹配关系

    Spring Cloud版本演进情况如下: 版本名称 版本Finchley snapshot版Edgware snapshot版Dalston SR1 当前最新稳定版本Camden SR7 稳定版本B ...

  7. Spring Boot 版本支持对应JDK

    转自:http://www.cnblogs.com/oumi/p/9241424.html 一.Spring Boot 版本支持 Spring Boot Spring Framework Java M ...

  8. Spring Boot 版本支持

    一.Spring Boot 版本支持 Spring Boot Spring Framework Java Maven Gradle 1.2.0之前版本   6 3.0+ 1.6+ 1.2.0 4.1. ...

  9. Spring Boot版本,Spring Cloud版本与组件版本关系

    我们在学习Spring Cloud时,可能总是碰到以下问题: 1.Spring Boot版本与Spring Cloud版本关系 2.启动时,报莫名其妙的错,稀里糊涂的换个版本就好了 3.这么多版本,用 ...

随机推荐

  1. C语言I作业004

    这个作业属于那个课程 C语言程序设计II 这个作业要求在哪里 作业 我在这个课程的目标是 掌握使用for循环语句实现指定次数的循环程序设计 这个作业在那个具体方面帮助我实现目标 pta运用for循环语 ...

  2. webstrom 永久激活方法 ,长期可用

    打开hosts文件:C:\Windows\System32\drivers\etc 在最后一行添加 0.0.0.0 account.jetbrains.com 打开webstorm,选择Activat ...

  3. SpringCloud教程一:eureka注册中心(Finchley版)

    一.spring cloud简介 本阶段学习教程Spring Boot版本2.0.3.RELEASE,Spring Cloud版本为Finchley.RELEASE. Finchley版本的官方文档如 ...

  4. python中函数调用---可变对象以及不可变对象

    # 定义函数 def demo(obj): print("原值: ",obj) obj += obj #调用函数 print("========值传递=======&qu ...

  5. Mysql数据类型最细讲解

    文章原创于公众号:程序猿周先森.本平台不定时更新,喜欢我的文章,欢迎关注我的微信公众号. 数据库中事务是最重要的概念之一,所以上篇着重谈了谈数据库中事务的使用,并且举了实例如何在实际开发中去使用事务进 ...

  6. Cocos2d-x入门之旅[4]场景

    我们之前讲了场景图(Scene Graph) 的概念,继续之前你先要知道 场景图决定了场景内节点对象的渲染顺序 渲染时 z-order 值大的节点对象会后绘制,值小的节点对象先绘制 HelloWorl ...

  7. 实用---eclipse中的代码提示功能

    Eclipse 的代码提示功能,具体配置 1. 打开Eclipse ,然后“window”→“Preferences” 2. 选择“java”,展开,“Editor”,选择“Content Assis ...

  8. opencv::像素重映射

    像素重映射(cv::remap) 简单点说就是把输入图像中各个像素按照一定的规则映射到另外一张图像的对应位置上去,形成一张新的图像. Remap( InputArray src, // 输入图像 Ou ...

  9. python-利用freeze生成requirements文件

    使用场景:本地电脑开发完成的python自动化项目,需要导出python相关的依赖包以便后续迁移项目使用. C:\Users\acer>e: E:\>pip freeze >requ ...

  10. 01jmeter-beanshell常用代码段

    1.获取时间 import java.util.*; import java.text.SimpleDateFormat; String str1 = (new SimpleDateFormat(&q ...