ServerProperties
Spring Boot 其默认是集成web容器的,启动⽅式由像普通Java程序⼀样,main函数⼊⼝启动。其内置Tomcat容器或Jetty容器,具体由配置来决定(默认Tomcat)。当然你也可以将项⽬打包成war包,放到独⽴的web容器中(Tomcat、weblogic等等),当然在此之前你要对程序⼊⼝做简单调整。
项⽬构建我们使⽤Maven或Gradle,这将使项⽬依赖、jar包管理、以及打包部署变的⾮常⽅便。
⼀、内嵌 Server 配置
Spring Boot将容器内置后,它通过配置⽂件的⽅式类修改相关server配置。
先看⼀下下⾯的图,为关于server的配置列项:
其中常⽤的配置只有少数⼏个,已经⽤紫⾊标记起来。红框圈起来的部分,看名称分类就可以明⽩其作⽤。
对server的⼏个常⽤的配置做个简单说明:
# 项⽬contextPath,⼀般在正式发布版本中,我们不配置
# 错误页,指定发⽣错误时,跳转的URL。请查看BasicErrorController源码便知
# 服务端⼝
server.port=9090
# session最⼤超时时间(分钟),默认为30
server.session-timeout=60
# 该服务绑定IP地址,启动服务器时如本机不是该IP地址则抛出异常启动失败,只有特殊需求的情况下才配置
# server.address=192.168.16.11
Tomcat
Tomcat为Spring Boot的默认容器,下⾯是⼏个常⽤配置:
1. # tomcat最⼤线程数,默认为200
2. at.max-threads=800
3. # tomcat的URI编码
4. at.uri-encoding=UTF-8
5. # 存放Tomcat的⽇志、Dump等⽂件的临时⽂件夹,默认为系统的tmp⽂件夹(如:C:\Users\Shanhy\AppData\Local\Temp)
6. at.basedir=H:/springboot-tomcat-tmp
7. # 打开Tomcat的Access⽇志,并可以设置⽇志格式的⽅法:
8. #at.access-log-enabled=true
9. #at.access-log-pattern=
10. # accesslog⽬录,默认在basedir/logs
11. #at.accesslog.directory=
12. # ⽇志⽂件⽬录
13. logging.path=H:/springboot-tomcat-tmp
14. # ⽇志⽂件名称,默认为spring.log
15. logging.file=myapp.log
wwwblogs/duyinqiang/p/5696342.html
org.springframework.boot:spring-boot-autoconfigure:1.3.0.M1
spring-boot-autoconfigure-1.3.0.M1.jar
org.springframework.boot.autoconfigure.web.ServerProperties
/*
* Copyright 2012-2015 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
*      /licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.boot.autoconfigure.web;
import java.io.File;
import java.InetAddress;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
import straints.NotNull;
import org.apache.catalina.Context;
import org.tor.Connector;
import org.apache.catalina.valves.AccessLogValve;
import org.apache.catalina.valves.RemoteIpValve;
properties在哪打开import AbstractProtocol;
import ProtocolHandler;
import http11.AbstractHttp11Protocol;
import org.t.embedded.ConfigurableEmbeddedServletContainer;
import org.t.embedded.EmbeddedServletContainerCustomizer;
import org.t.embedded.EmbeddedServletContainerCustomizerBeanPostProcessor; import org.t.embedded.EmbeddedServletContainerFactory;
import org.t.embedded.InitParameterConfiguringServletContextInitializer;
import org.t.embedded.JspServlet;
import org.t.embedded.Ssl;
import org.at.TomcatConnectorCustomizer;
import org.at.TomcatContextCustomizer;
import org.at.TomcatEmbeddedServletContainerFactory; import org.t.embedded.undertow.UndertowEmbeddedServletContainerFactory; import org.t.properties.ConfigurationProperties;
import org.t.properties.NestedConfigurationProperty;
import Ordered;
import org.springframework.util.StringUtils;
/**
* {@link ConfigurationProperties} for a web server (e.g. port and path settings). Will be
* used to customize an {@link EmbeddedServletContainerFactory} when an
* {@link EmbeddedServletContainerCustomizerBeanPostProcessor} is active.
*
* @author Dave Syer
* @author Stephane Nicoll
* @author Andy Wilkinson
* @author Ivan Sopov
* @author Marcos Barbero
*/
server", ignoreUnknownFields = false)
@ConfigurationProperties(prefix = "
public class ServerProperties implements EmbeddedServletContainerCustomizer, Ordered {
/
**
* Server HTTP port.
*/
private Integer port;
/**
* Network address to which the server should bind to.
*/
private InetAddress address;
/**
* Session timeout in seconds.
*/
private Integer sessionTimeout;
/**
* Context path of the application.
*/
private String contextPath;
/**
* Display name of the application.
*/
private String displayName = "application";
@NestedConfigurationProperty
private Ssl ssl;
/
**
* Path of the main dispatcher servlet.
*/
@NotNull
private String servletPath = "/";
private final Tomcat tomcat = new Tomcat();
private final Undertow undertow = new Undertow();
@NestedConfigurationProperty
private JspServlet jspServlet;
/**
* ServletContext parameters.
*/
private final Map<String, String> contextParameters = new HashMap<String, String>();  @Override
public int getOrder() {
return 0;
}
public Tomcat getTomcat() {
at;
}
public Undertow getUndertow() {
return this.undertow;
}
public String getContextPath() {
tPath;
}
public void setContextPath(String contextPath) {
}
public String getDisplayName() {
return this.displayName;
}
public void setDisplayName(String displayName) {
this.displayName = displayName;
}
public String getServletPath() {
return this.servletPath;
}
public String getServletMapping() {
if (this.servletPath.equals("") || this.servletPath.equals("/")) {
return "/";
}
if (ains("*")) {
return this.servletPath;
}
if (dsWith("/")) {
return this.servletPath + "*";
}
return this.servletPath + "/*";
}
public String getServletPrefix() {
String result = this.servletPath;
if (ains("*")) {
result = result.substring(0, result.indexOf("*"));
}
if (dsWith("/")) {
result = result.substring(0, result.length() - 1);
}
return result;
}
public void setServletPath(String servletPath) {
this.servletPath = servletPath;
}
public Integer getPort() {
return this.port;
}
public void setPort(Integer port) {
this.port = port;
}
public InetAddress getAddress() {
return this.address;
}
public void setAddress(InetAddress address) {
this.address = address;
}
public Integer getSessionTimeout() {
return this.sessionTimeout;
}
public void setSessionTimeout(Integer sessionTimeout) {
this.sessionTimeout = sessionTimeout;
}
public Ssl getSsl() {
return this.ssl;
}
public void setSsl(Ssl ssl) {
this.ssl = ssl;
}
public JspServlet getJspServlet() {
return this.jspServlet;
}
public void setJspServlet(JspServlet jspServlet) {
this.jspServlet = jspServlet;
}
public Map<String, String> getContextParameters() {
tParameters;
}
public void setLoader(String value) {
// no op to support Tomcat running as a traditional container (not embedded)
}
@Override
public void customize(ConfigurableEmbeddedServletContainer container) {
if (getPort() != null) {
container.setPort(getPort());
}
if (getAddress() != null) {
container.setAddress(getAddress());
}
if (getContextPath() != null) {
container.setContextPath(getContextPath());
}
if (getDisplayName() != null) {
container.setDisplayName(getDisplayName());
}
if (getSessionTimeout() != null) {
container.setSessionTimeout(getSessionTimeout());
}
if (getSsl() != null) {
container.setSsl(getSsl());
}
if (getJspServlet() != null) {
container.setJspServlet(getJspServlet());
}
if (container instanceof TomcatEmbeddedServletContainerFactory) {
getTomcat()
.customizeTomcat((TomcatEmbeddedServletContainerFactory) container);      }
if (container instanceof UndertowEmbeddedServletContainerFactory) {
getUndertow().customizeUndertow(
(UndertowEmbeddedServletContainerFactory) container);
}
container.addInitializers(new InitParameterConfiguringServletContextInitializer(            getContextParameters()));
}
public String[] getPathsArray(Collection<String> paths) {
String[] result = new String[paths.size()];
int i = 0;
for (String path : paths) {
result[i++] = getPath(path);
}
return result;
}
public String[] getPathsArray(String[] paths) {
String[] result = new String[paths.length];
int i = 0;
for (String path : paths) {
result[i++] = getPath(path);
}
return result;
}
public String getPath(String path) {
String prefix = getServletPrefix();
if (!path.startsWith("/")) {
path = "/" + path;
}
return prefix + path;
}
public static class Tomcat {
/
**
* Format pattern for access logs.
*/
private String accessLogPattern;
/**
* Enable access log.
*/
private boolean accessLogEnabled = false;
/**
* Regular expression that matches proxies that are to be trusted.
*/
private String internalProxies = "10\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}|" // 10/8
+ "192\\.168\\.\\d{1,3}\\.\\d{1,3}|" // 192.168/16
+ "169\\.254\\.\\d{1,3}\\.\\d{1,3}|" // 169.254/16
+ "127\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}|" // 127/8
+ "172\\.1[6-9]{1}\\.\\d{1,3}\\.\\d{1,3}|" // 172.16/12
+ "172\\.2[0-9]{1}\\.\\d{1,3}\\.\\d{1,3}|"
+ "172\\.3[0-1]{1}\\.\\d{1,3}\\.\\d{1,3}";
/**
* Header that holds the incoming protocol, usually named "X-Forwarded-Proto".      * Configured as a RemoteIpValve only if remoteIpHeader is also set.
*/
private String protocolHeader;
/**
* Name of the HTTP header used to override the original port value.
*/
private String portHeader;
/**
* Name of the http header from which the remote ip is extracted. Configured as a        * RemoteIpValve only if remoteIpHeader is also set.
*/
private String remoteIpHeader;
/**
* Tomcat base directory. If not specified a temporary directory will be used.
*/
private File basedir;
/**
* Delay in seconds between the invocation of backgroundProcess methods.
*/
private int backgroundProcessorDelay = 30; // seconds
/**
* Maximum amount of worker threads.
*/
private int maxThreads = 0; // Number of threads in protocol handler /**
* Maximum size in bytes of the HTTP message header.
*/
private int maxHttpHeaderSize = 0; // bytes
/**
* Character encoding to use to decode the URI.
*/
private String uriEncoding;
/**
* Controls response compression. Acceptable values are "off" to disable
* compression, "on" to enable compression of responses over 2048 bytes, "force"

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。