Spring Boot Tomcat配置

参数配置容器

server.xx开头的是所有servlet容器通用的配置,server.tomcat.xx开头的是tomcat特有的参数,其它类似。

所有参数绑定配置类:org.springframework.boot.autoconfigure.web.ServerProperties

1# EMBEDDED SERVER CONFIGURATION (ServerProperties) 2server.address= # Network address to which the server should bind to. 3server.compression.enabled=false # If response compression is enabled. 4server.compression.excluded-user-agents= # List of user-agents to exclude from compression. 5server.compression.mime-types= # Comma-separated list of MIME types that should be compressed. For instance `text/html,text/css,application/json` 6server.compression.min-response-size= # Minimum response size that is required for compression to be performed. For instance 2048 7server.connection-timeout= # Time in milliseconds that connectors will wait for another HTTP request before closing the connection. When not set, the connector's container-specific default will be used. Use a value of -1 to indicate no (i.e. infinite) timeout. 8server.display-name=application # Display name of the application. 9server.max-http-header-size=0 # Maximum size in bytes of the HTTP message header. 10server.error.include-exception=false # Include the "exception" attribute. 11server.error.include-stacktrace=never # When to include a "stacktrace" attribute. 12server.error.path=/error # Path of the error controller. 13server.error.whitelabel.enabled=true # Enable the default error page displayed in browsers in case of a server error. 14server.jetty.acceptors= # Number of acceptor threads to use. 15server.jetty.accesslog.append=false # Append to log. 16server.jetty.accesslog.date-format=dd/MMM/yyyy:HH:mm:ss Z # Timestamp format of the request log. 17server.jetty.accesslog.enabled=false # Enable access log. 18server.jetty.accesslog.extended-format=false # Enable extended NCSA format. 19server.jetty.accesslog.file-date-format= # Date format to place in log file name. 20server.jetty.accesslog.filename= # Log filename. If not specified, logs will be redirected to "System.err". 21server.jetty.accesslog.locale= # Locale of the request log. 22server.jetty.accesslog.log-cookies=false # Enable logging of the request cookies. 23server.jetty.accesslog.log-latency=false # Enable logging of request processing time. 24server.jetty.accesslog.log-server=false # Enable logging of the request hostname. 25server.jetty.accesslog.retention-period=31 # Number of days before rotated log files are deleted. 26server.jetty.accesslog.time-zone=GMT # Timezone of the request log. 27server.jetty.max-http-post-size=0 # Maximum size in bytes of the HTTP post or put content. 28server.jetty.selectors= # Number of selector threads to use. 29server.port=8080 # Server HTTP port. 30server.server-header= # Value to use for the Server response header (no header is sent if empty) 31server.use-forward-headers= # If X-Forwarded-* headers should be applied to the HttpRequest. 32server.servlet.context-parameters.*= # Servlet context init parameters 33server.servlet.context-path= # Context path of the application. 34server.servlet.jsp.class-name=org.apache.jasper.servlet.JspServlet # The class name of the JSP servlet. 35server.servlet.jsp.init-parameters.*= # Init parameters used to configure the JSP servlet 36server.servlet.jsp.registered=true # Whether or not the JSP servlet is registered 37server.servlet.path=/ # Path of the main dispatcher servlet. 38server.session.cookie.comment= # Comment for the session cookie. 39server.session.cookie.domain= # Domain for the session cookie. 40server.session.cookie.http-only= # "HttpOnly" flag for the session cookie. 41server.session.cookie.max-age= # Maximum age of the session cookie in seconds. 42server.session.cookie.name= # Session cookie name. 43server.session.cookie.path= # Path of the session cookie. 44server.session.cookie.secure= # "Secure" flag for the session cookie. 45server.session.persistent=false # Persist session data between restarts. 46server.session.servlet.filter-order=-2147483598 # Session repository filter order. 47server.session.servlet.filter-dispatcher-types=ASYNC, ERROR, REQUEST # Session repository filter dispatcher types. 48server.session.store-dir= # Directory used to store session data. 49server.session.timeout= # Session timeout in seconds. 50server.session.tracking-modes= # Session tracking modes (one or more of the following: "cookie", "url", "ssl"). 51server.ssl.ciphers= # Supported SSL ciphers. 52server.ssl.client-auth= # Whether client authentication is wanted ("want") or needed ("need"). Requires a trust store. 53server.ssl.enabled= # Enable SSL support. 54server.ssl.enabled-protocols= # Enabled SSL protocols. 55server.ssl.key-alias= # Alias that identifies the key in the key store. 56server.ssl.key-password= # Password used to access the key in the key store. 57server.ssl.key-store= # Path to the key store that holds the SSL certificate (typically a jks file). 58server.ssl.key-store-password= # Password used to access the key store. 59server.ssl.key-store-provider= # Provider for the key store. 60server.ssl.key-store-type= # Type of the key store. 61server.ssl.protocol=TLS # SSL protocol to use. 62server.ssl.trust-store= # Trust store that holds SSL certificates. 63server.ssl.trust-store-password= # Password used to access the trust store. 64server.ssl.trust-store-provider= # Provider for the trust store. 65server.ssl.trust-store-type= # Type of the trust store. 66server.tomcat.accept-count= # Maximum queue length for incoming connection requests when all possible request processing threads are in use. 67server.tomcat.accesslog.buffered=true # Buffer output such that it is only flushed periodically. 68server.tomcat.accesslog.directory=logs # Directory in which log files are created. Can be relative to the tomcat base dir or absolute. 69server.tomcat.accesslog.enabled=false # Enable access log. 70server.tomcat.accesslog.file-date-format=.yyyy-MM-dd # Date format to place in log file name. 71server.tomcat.accesslog.pattern=common # Format pattern for access logs. 72server.tomcat.accesslog.prefix=access_log # Log file name prefix. 73server.tomcat.accesslog.rename-on-rotate=false # Defer inclusion of the date stamp in the file name until rotate time. 74server.tomcat.accesslog.request-attributes-enabled=false # Set request attributes for IP address, Hostname, protocol and port used for the request. 75server.tomcat.accesslog.rotate=true # Enable access log rotation. 76server.tomcat.accesslog.suffix=.log # Log file name suffix. 77server.tomcat.additional-tld-skip-patterns= # Comma-separated list of additional patterns that match jars to ignore for TLD scanning. 78server.tomcat.background-processor-delay=30 # Delay in seconds between the invocation of backgroundProcess methods. 79server.tomcat.basedir= # Tomcat base directory. If not specified a temporary directory will be used. 80server.tomcat.internal-proxies=10\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}|\\ 81 192\\.168\\.\\d{1,3}\\.\\d{1,3}|\\ 82 169\\.254\\.\\d{1,3}\\.\\d{1,3}|\\ 83 127\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}|\\ 84 172\\.1[6-9]{1}\\.\\d{1,3}\\.\\d{1,3}|\\ 85 172\\.2[0-9]{1}\\.\\d{1,3}\\.\\d{1,3}|\\ 86 172\\.3[0-1]{1}\\.\\d{1,3}\\.\\d{1,3} # regular expression matching trusted IP addresses. 87server.tomcat.max-connections= # Maximum number of connections that the server will accept and process at any given time. 88server.tomcat.max-http-header-size=0 # Maximum size in bytes of the HTTP message header. 89server.tomcat.max-http-post-size=0 # Maximum size in bytes of the HTTP post content. 90server.tomcat.max-threads=0 # Maximum amount of worker threads. 91server.tomcat.min-spare-threads=0 # Minimum amount of worker threads. 92server.tomcat.port-header=X-Forwarded-Port # Name of the HTTP header used to override the original port value. 93server.tomcat.protocol-header= # Header that holds the incoming protocol, usually named "X-Forwarded-Proto". 94server.tomcat.protocol-header-https-value=https # Value of the protocol header that indicates that the incoming request uses SSL. 95server.tomcat.redirect-context-root= # Whether requests to the context root should be redirected by appending a / to the path. 96server.tomcat.remote-ip-header= # Name of the http header from which the remote ip is extracted. For instance `X-FORWARDED-FOR` 97server.tomcat.uri-encoding=UTF-8 # Character encoding to use to decode the URI. 98server.undertow.accesslog.dir= # Undertow access log directory. 99server.undertow.accesslog.enabled=false # Enable access log. 100server.undertow.accesslog.pattern=common # Format pattern for access logs. 101server.undertow.accesslog.prefix=access_log. # Log file name prefix. 102server.undertow.accesslog.rotate=true # Enable access log rotation. 103server.undertow.accesslog.suffix=log # Log file name suffix. 104server.undertow.buffer-size= # Size of each buffer in bytes. 105server.undertow.direct-buffers= # Allocate buffers outside the Java heap. 106server.undertow.io-threads= # Number of I/O threads to create for the worker. 107server.undertow.eager-filter-init=true # Whether servlet filters should be initialized on startup. 108server.undertow.max-http-post-size=0 # Maximum size in bytes of the HTTP post content. 109server.undertow.worker-threads= # Number of worker threads.

代码配置容器

除了利用上面的参数来自动配置servlet容器,还可以通过代码的方式。可以直接实现EmbeddedServletContainerCustomizer这个接口,ServerProperties也是实现这个接口的。

1@ConfigurationProperties(prefix = "server", ignoreUnknownFields = true) 2public class ServerProperties 3 implements EmbeddedServletContainerCustomizer, EnvironmentAware, Ordered { 4...

当然如果是Tomcat、Jetty、Undertow也可以使用下面对应的特定的容器工厂类。

1// Jetty 2org.springframework.boot.context.embedded.jetty.JettyEmbeddedServletContainerFactory 3 4// Tomcat 5org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainerFactory 6 7// Undertow 8org.springframework.boot.context.embedded.undertow.UndertowEmbeddedServletContainerFactory

替换Tomcat

spring-boot-starter-web brings Tomcat with spring-boot-starter-tomcat, but spring-boot-starter-jetty and spring-boot-starter-undertow can be used instead.

spring-boot-starter-web自动携带了tomcat依赖,但也可以替换成jetty和undertow,下面是一个替换jetty的示例。

1<dependency> 2 <groupId>org.springframework.boot</groupId> 3 <artifactId>spring-boot-starter-web</artifactId> 4 <exclusions> 5 <!-- Exclude the Tomcat dependency --> 6 <exclusion> 7 <groupId>org.springframework.boot</groupId> 8 <artifactId>spring-boot-starter-tomcat</artifactId> 9 </exclusion> 10 </exclusions> 11</dependency> 12<!-- Use Jetty instead --> 13<dependency> 14 <groupId>org.springframework.boot</groupId> 15 <artifactId>spring-boot-starter-jetty</artifactId> 16</dependency>

推荐:Spring Boot & Cloud 最强技术教程

扫描关注我们的微信公众号,干货每天更新。

image

点赞
收藏

评论区

加载中...

相关推荐

MySQL:[Err] 1292 - Incorrect datetime value: ‘0000-00-00 00:00:00‘ for column ‘CREATE_TIME‘ at row 1

文章目录问题用navicat导入数据时,报错:原因这是因为当前的MySQL不支持datetime为0的情况。解决修改sql\mode:sql\mode:SQLMode定义了MySQL应支持的SQL语法、数据校验等,这样可以更容易地在不同的环境中使用MySQL。全局s

Oracle 分组与拼接字符串同时使用

SELECTT.,ROWNUMIDFROM(SELECTT.EMPLID,T.NAME,T.BU,T.REALDEPART,T.FORMATDATE,SUM(T.S0)S0,MAX(UPDATETIME)CREATETIME,LISTAGG(TOCHAR(

MySQL部分从库上面因为大量的临时表tmp_table造成慢查询

背景描述Time:20190124T00:08:14.70572408:00User@Host:@Id:Schema:sentrymetaLast_errno:0Killed:0Query_time:0.315758Lock_

皕杰报表之UUID

​在我们用皕杰报表工具设计填报报表时,如何在新增行里自动增加id呢?能新增整数排序id吗?目前可以在新增行里自动增加id,但只能用uuid函数增加UUID编码,不能新增整数排序id。uuid函数说明:获取一个UUID,可以在填报表中用来创建数据ID语法:uuid()或uuid(sep)参数说明:sep布尔值,生成的uuid中是否包含分隔符'',缺省为

手写Java HashMap源码

HashMap的使用教程HashMap的使用教程HashMap的使用教程HashMap的使用教程HashMap的使用教程22

2020年前端实用代码段,为你的工作保驾护航

有空的时候,自己总结了几个代码段,在开发中也经常使用,谢谢。1、使用解构获取json数据let jsonData  id: 1,status: "OK",data: 'a', 'b';let  id, status, data: number   jsonData;console.log(id, status, number )