https://blog.csdn.net/wd2014610/article/details/79587161

2018年春SpringBoot 2.0.0 新版本有了很多新的改变,其中Tomcat配置上也有了很大改变
1、之前老的版本TomcatEmbeddedServletContainerFactory取的是这个类

2、在SpringBoot 2.0.0框架中,已经没有类TomcatEmbeddedServletContainerFactory了

3、在老版本的Tomcat配置中,构造tomcatFactory的bean

@Bean
public TomcatEmbeddedServletContainerFactory tomcatFactory() {
TomcatEmbeddedServletContainerFactory tomcatFactory = new TomcatEmbeddedServletContainerFactory();
tomcatFactory.addConnectorCustomizers(new GwsTomcatConnectionCustomizer());
return tomcatFactory;
}
1
2
3
4
5
6
4、那么早SpringBoot 2.0.0中该怎么构建呢?
去到SpringBoot官方文档这里写链接内容、找到Tomcat配置

5、最新的已经有了全新的类了

6、事例

7、那么就可以用全新的ServletWebServerFactory类来构造Tomcat的配置了

@Bean
public ServletWebServerFactory servletContainer() {
TomcatServletWebServerFactory tomcat = new TomcatServletWebServerFactory();
tomcat.addConnectorCustomizers(new GwsTomcatConnectionCustomizer());
return tomcat;
}
1
2
3
4
5
6
8、最后附上全新的Tomcat配置

package com.gws.configuration;

import org.apache.catalina.connector.Connector;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.web.embedded.tomcat.TomcatConnectorCustomizer;
import org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory;
import org.springframework.boot.web.servlet.MultipartConfigFactory;
import org.springframework.boot.web.servlet.server.ServletWebServerFactory;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import javax.servlet.MultipartConfigElement;

/**
* 使用tomcat配置
*
* @version
* @author
*
*/
@Configuration
public class TomcatConfig {

@Value("${spring.server.port}")
private String port;
@Value("${spring.server.acceptorThreadCount}")
private String acceptorThreadCount;
@Value("${spring.server.minSpareThreads}")
private String minSpareThreads;
@Value("${spring.server.maxSpareThreads}")
private String maxSpareThreads;
@Value("${spring.server.maxThreads}")
private String maxThreads;
@Value("${spring.server.maxConnections}")
private String maxConnections;
@Value("${spring.server.protocol}")
private String protocol;
@Value("${spring.server.redirectPort}")
private String redirectPort;
@Value("${spring.server.compression}")
private String compression;
@Value("${spring.server.connectionTimeout}")
private String connectionTimeout;

@Value("${spring.server.MaxFileSize}")
private String MaxFileSize;
@Value("${spring.server.MaxRequestSize}")
private String MaxRequestSize;

@Bean
public ServletWebServerFactory servletContainer() {
TomcatServletWebServerFactory tomcat = new TomcatServletWebServerFactory();
tomcat.addConnectorCustomizers(new GwsTomcatConnectionCustomizer());
return tomcat;
}

@Bean
public MultipartConfigElement multipartConfigElement() {
MultipartConfigFactory factory = new MultipartConfigFactory();
// 单个数据大小
factory.setMaxFileSize(MaxFileSize); // KB,MB
/// 总上传数据大小
factory.setMaxRequestSize(MaxRequestSize);
return factory.createMultipartConfig();
}

/**
*
* 默认http连接
*
* @version
* @author liuyi 2016年7月20日 下午7:59:41
*
*/
public class GwsTomcatConnectionCustomizer implements TomcatConnectorCustomizer {

public GwsTomcatConnectionCustomizer() {
}

@Override
public void customize(Connector connector) {
connector.setPort(Integer.valueOf(port));
connector.setAttribute("connectionTimeout", connectionTimeout);
connector.setAttribute("acceptorThreadCount", acceptorThreadCount);
connector.setAttribute("minSpareThreads", minSpareThreads);
connector.setAttribute("maxSpareThreads", maxSpareThreads);
connector.setAttribute("maxThreads", maxThreads);
connector.setAttribute("maxConnections", maxConnections);
connector.setAttribute("protocol", protocol);
connector.setAttribute("redirectPort", "redirectPort");
connector.setAttribute("compression", "compression");
}
}
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
9、最后在application.properties,进行配置

#嵌入tomcat配置
spring.server.port=8095
#和CPU数
spring.server.acceptorThreadCount=4
spring.server.minSpareThreads=50
spring.server.maxSpareThreads=50
spring.server.maxThreads=1000
spring.server.maxConnections=10000
#10秒超时
spring.server.connectionTimeout=10000
spring.server.protocol=org.apache.coyote.http11.Http11Nio2Protocol
spring.server.redirectPort=443
spring.server.compression=on
#文件请求大小
spring.server.MaxFileSize=300MB
spring.server.MaxRequestSize=500MB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
10、好了,搞定了

【转】SpringBoot 2.0.0新版和SpringBoot1.5.2版本中Tomcat配置的差别的更多相关文章

  1. springboot升级2.0 fastjson报错? 2.0以上应该怎么整合fastjson?

    SpringBoot2.0如何集成fastjson?在网上查了一堆资料,但是各文章的说法不一,有些还是错的,可能只是简单测试一下就认为ok了,最后有没生效都不知道.恰逢公司项目需要将JackSon换成 ...

  2. SpringBoot启动使用elasticsearch启动异常:Received message from unsupported version:[2.0.0] minimal compatible

    SpringBoot启动使用elasticsearch启动异常:Received message from unsupported version:[2.0.0] minimal compatible ...

  3. 探索Antlr(Antlr 3.0更新版)

    版权声明:转载时请以超链接形式标明文章原始出处和作者信息及本声明 http://www.blogbus.com/dreamhead-logs/10756716.html <探索Antlr> ...

  4. SpringBoot入门教程(二)CentOS部署SpringBoot项目从0到1

    在之前的博文<详解intellij idea搭建SpringBoot>介绍了idea搭建SpringBoot的详细过程, 并在<CentOS安装Tomcat>中介绍了Tomca ...

  5. PHPCMS9.6.0最新版SQL注入和前台GETSHELL漏洞分析 (实验新课)

    PHPCMS9.6.0最新版中,由于/modules/attachment/attachments.php的过滤函数的缺陷导致了可以绕过它的过滤机制形成SQL注入漏洞,可导致数据库中数据泄漏. 而且在 ...

  6. SpringBoot之oauth2.0学习之服务端配置快速上手

    现在第三方登录的例子数见不鲜.其实在这种示例当中,oauth2.0是使用比较多的一种授权登录的标准.oauth2.0也是从oauth1.0升级过来的.那么关于oauth2.0相关的概念及其原理,大家可 ...

  7. SpringBoot集成Mybatis(0配置注解版)

    Mybatis初期使用比较麻烦,需要各种配置文件.实体类.dao层映射关联.还有一大推其它配置.当然Mybatis也发现了这种弊端,初期开发了generator可以根据表结构自动生成实体类.配置文件和 ...

  8. SpringBoot整合Graylog3.0

    Graylog简介 Graylog是一个开源的完整的日志管理工具,功能和ELK类似,安装部署更方便. 官方网站 https://www.graylog.org 搭建 使用docker快速搭建 参考 h ...

  9. 《Drools7.0.0.Final规则引擎教程》Springboot+规则重新加载

    在<Drools7.0.0.Final规则引擎教程>之Springboot集成中介绍了怎样将Drools与Springboot进行集成,本篇博客介绍一下集成之后,如何实现从数据库读取规则并 ...

随机推荐

  1. OpenCV入门指南

    http://blog.csdn.net/morewindows/article/details/8225783/ http://blog.csdn.net/poem_qianmo/article/d ...

  2. UnityEngine中Animator相关类的说明

    ---------------------------------------------------------------------- Animator 这个单独写,比较多 AnimationC ...

  3. OPENGL0_简介

    opengl定义: Open Graphics Library,开放图形程序接口,跨平台,跨语言.提供了与底层图形硬件的接口,是一个功能强大的底层图形库. opengl库种类: gl:核心库,常规,核 ...

  4. [HNOI2010] 物品调度 fsk

    标签:链表+数论知识. 题解: 对于这道题,其实就是两个问题的拼凑,我们分开来看. 首先要求xi与yi.这个可以发现,x每增加1,则pos增加d:y每增加1,则pos增加1.然后,我们把x与y分别写在 ...

  5. 剑指OFFER之最大子向量和(连续子数组的最大和)(九度OJ1372)

    题目描述: HZ偶尔会拿些专业问题来忽悠那些非计算机专业的同学.今天JOBDU测试组开完会后,他又发话了:在古老的一维模式识别中,常常需要计算连续子向量的最大和,当向量全为正数的时候,问题很好解决.但 ...

  6. 微信小程序云开发之云函数的创建与环境配置

    云函数的使用与环境配置: 1.创建云函数 右键cloudfunctions文件选择新建Node.js云函数,云函数命名为updateVoice用于修改用户语音数量. 2.安装node.js及npm: ...

  7. windows 自定义批处理BAT/CMD启动Redis等软件

    需求:每次开机都需要启动Redis.QQ.IDEA等等好几个软件,手动点击比较无趣.浪费劳动力,所以通过自定义bat文件,进行批量启动. 唯独启动到Redis时出现问题,下面是在bat里运行的路径: ...

  8. JS与JQ的对比与提高

    来吧, 案例1:先上个例子js写的省市二级联动 <!DOCTYPE html><html> <head> <meta charset="UTF-8& ...

  9. Pycharm2018.3.1永久激活

    Pycharm Professional 2018.3.1 版已正式发布,新版本添加对Python3.7的支持.作为强大的开发工具,但每次注册让人头疼,本着分享的心态,提供以下解决方案,亲测有效!本方 ...

  10. 测试 | 单元测试工具 | JUnit

    http://junit.sourceforge.net/javadoc/org/junit/Assert.html 使用: 新建测试类: 在预测试的类上点击右键--->NEW--->Ju ...