【转】SpringBoot 2.0.0新版和SpringBoot1.5.2版本中Tomcat配置的差别
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配置的差别的更多相关文章
- springboot升级2.0 fastjson报错? 2.0以上应该怎么整合fastjson?
SpringBoot2.0如何集成fastjson?在网上查了一堆资料,但是各文章的说法不一,有些还是错的,可能只是简单测试一下就认为ok了,最后有没生效都不知道.恰逢公司项目需要将JackSon换成 ...
- SpringBoot启动使用elasticsearch启动异常:Received message from unsupported version:[2.0.0] minimal compatible
SpringBoot启动使用elasticsearch启动异常:Received message from unsupported version:[2.0.0] minimal compatible ...
- 探索Antlr(Antlr 3.0更新版)
版权声明:转载时请以超链接形式标明文章原始出处和作者信息及本声明 http://www.blogbus.com/dreamhead-logs/10756716.html <探索Antlr> ...
- SpringBoot入门教程(二)CentOS部署SpringBoot项目从0到1
在之前的博文<详解intellij idea搭建SpringBoot>介绍了idea搭建SpringBoot的详细过程, 并在<CentOS安装Tomcat>中介绍了Tomca ...
- PHPCMS9.6.0最新版SQL注入和前台GETSHELL漏洞分析 (实验新课)
PHPCMS9.6.0最新版中,由于/modules/attachment/attachments.php的过滤函数的缺陷导致了可以绕过它的过滤机制形成SQL注入漏洞,可导致数据库中数据泄漏. 而且在 ...
- SpringBoot之oauth2.0学习之服务端配置快速上手
现在第三方登录的例子数见不鲜.其实在这种示例当中,oauth2.0是使用比较多的一种授权登录的标准.oauth2.0也是从oauth1.0升级过来的.那么关于oauth2.0相关的概念及其原理,大家可 ...
- SpringBoot集成Mybatis(0配置注解版)
Mybatis初期使用比较麻烦,需要各种配置文件.实体类.dao层映射关联.还有一大推其它配置.当然Mybatis也发现了这种弊端,初期开发了generator可以根据表结构自动生成实体类.配置文件和 ...
- SpringBoot整合Graylog3.0
Graylog简介 Graylog是一个开源的完整的日志管理工具,功能和ELK类似,安装部署更方便. 官方网站 https://www.graylog.org 搭建 使用docker快速搭建 参考 h ...
- 《Drools7.0.0.Final规则引擎教程》Springboot+规则重新加载
在<Drools7.0.0.Final规则引擎教程>之Springboot集成中介绍了怎样将Drools与Springboot进行集成,本篇博客介绍一下集成之后,如何实现从数据库读取规则并 ...
随机推荐
- HTML中 &emsp等空格的区别
HTML提供了5种空格实体(space entity),它们拥有不同的宽度,非断行空格( )是常规空格的宽度,可运行于所有主流浏览器.其他几种空格( )在不同浏览器中宽度各异. ...
- 洛谷 - P1072 Hankson - 的趣味题 - 质因数分解
https://www.luogu.org/problemnew/show/P1072 一开始看了一看居然还想放弃了的. 把 \(x,a_0,a_1,b_0,b_1\) 质因数分解. 例如 \(x=p ...
- html扩展调用qq聊天窗口
需要在官方给qq开通客服功能,使用相应的html代码,别人才能通过链接调用到该qq 官方生成调用链接 over!over!over!
- C# sbyte[]转byte[]
http://stackoverflow.com/questions/2995639/sbyte-vs-byte-using-methodssbyte[] orig = ... byte[] arr ...
- Lightoj1000【简单A+B】
balababalabalabala! #include<stdio.h> #include<queue> #include<string.h> #include& ...
- NDAP 日志
2014.04.29 1.理论债券价格CalculateExpetedBondPrice计算有误差 CalculateLibrary中的计算理论债券价格(计算理论期货价格的反函数)和正确结果有误差(可 ...
- [Xcode 实际操作]七、文件与数据-(16)解析XML文档
目录:[Swift]Xcode实际操作 本文将演示如何解析XML文档. 项目中已添加一份XML文档:worker.xml <?xml version="1.0" encodi ...
- mysql--浅谈视图1
这是对自己学习燕十八老师mysql教程的总结,非常感谢燕十八老师. 依赖软件:mysql5.6 系统环境:win 视图(view) 什么是视图? 答:视图是表通过某种运算得到的一个投影,占有一定空间的 ...
- 上传到git
https://blog.csdn.net/Lucky_LXG/article/details/77849212
- samba服务器实验指导
第一节.samba是干什么的?它有什么用? Samba(SMB是其缩写) 是一个网络服务器,它是Linux作为本地服务器最重要的一个服务,用于Linux和Windows共享文件之用:Samba可以用于 ...