Spring Boot 其默认是集成web容器的,启动方式由像普通Java程序一样,main函数入口启动。其内置Tomcat容器或Jetty容器,具体由配置来决定(默认Tomcat)。当然你也可以将项目打包成war包,放到独立的web容器中(Tomcat、weblogic等等),当然在此之前你要对程序入口做简单调整。

项目构建我们使用Maven或Gradle,这将使项目依赖、jar包管理、以及打包部署变的非常方便。

一、内嵌 Server 配置

Spring Boot将容器内置后,它通过配置文件的方式类修改相关server配置。
先看一下下面的图,为关于server的配置列项:

其中常用的配置只有少数几个,已经用紫色标记起来。红框圈起来的部分,看名称分类就可以明白其作用。
对server的几个常用的配置做个简单说明:

# 项目contextPath,一般在正式发布版本中,我们不配置
server.context-path=/myspringboot
# 错误页,指定发生错误时,跳转的URL。请查看BasicErrorController源码便知
server.error.path=/error
# 服务端口
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. server.tomcat.max-threads=800
    3. # tomcat的URI编码
    4. server.tomcat.uri-encoding=UTF-8
    5. # 存放Tomcat的日志、Dump等文件的临时文件夹,默认为系统的tmp文件夹(如:C:\Users\Shanhy\AppData\Local\Temp)
    6. server.tomcat.basedir=H:/springboot-tomcat-tmp
    7. # 打开Tomcat的Access日志,并可以设置日志格式的方法:
    8. #server.tomcat.access-log-enabled=true
    9. #server.tomcat.access-log-pattern=
    10. # accesslog目录,默认在basedir/logs
    11. #server.tomcat.accesslog.directory=
    12. # 日志文件目录
    13. logging.path=H:/springboot-tomcat-tmp
    14. # 日志文件名称,默认为spring.log
    15. logging.file=myapp.log
http://www.cnblogs.com/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
*
* http://www.apache.org/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.net.InetAddress;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map; import javax.validation.constraints.NotNull; import org.apache.catalina.Context;
import org.apache.catalina.connector.Connector;
import org.apache.catalina.valves.AccessLogValve;
import org.apache.catalina.valves.RemoteIpValve;
import org.apache.coyote.AbstractProtocol;
import org.apache.coyote.ProtocolHandler;
import org.apache.coyote.http11.AbstractHttp11Protocol;
import org.springframework.boot.context.embedded.ConfigurableEmbeddedServletContainer;
import org.springframework.boot.context.embedded.EmbeddedServletContainerCustomizer;
import org.springframework.boot.context.embedded.EmbeddedServletContainerCustomizerBeanPostProcessor;
import org.springframework.boot.context.embedded.EmbeddedServletContainerFactory;
import org.springframework.boot.context.embedded.InitParameterConfiguringServletContextInitializer;
import org.springframework.boot.context.embedded.JspServlet;
import org.springframework.boot.context.embedded.Ssl;
import org.springframework.boot.context.embedded.tomcat.TomcatConnectorCustomizer;
import org.springframework.boot.context.embedded.tomcat.TomcatContextCustomizer;
import org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainerFactory;
import org.springframework.boot.context.embedded.undertow.UndertowEmbeddedServletContainerFactory;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.context.properties.NestedConfigurationProperty;
import org.springframework.core.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
*/
@ConfigurationProperties(prefix = "server", ignoreUnknownFields = false)
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() {
return this.tomcat;
} public Undertow getUndertow() {
return this.undertow;
} public String getContextPath() {
return this.contextPath;
} public void setContextPath(String contextPath) {
this.contextPath = 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 (this.servletPath.contains("*")) {
return this.servletPath;
}
if (this.servletPath.endsWith("/")) {
return this.servletPath + "*";
}
return this.servletPath + "/*";
} public String getServletPrefix() {
String result = this.servletPath;
if (result.contains("*")) {
result = result.substring(0, result.indexOf("*"));
}
if (result.endsWith("/")) {
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() {
return this.contextParameters;
} 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"
* to force response compression, or an integer value to enable compression of
* responses with content length that is at least that value.
*/
private String compression = "off"; /**
* Comma-separated list of MIME types for which compression is used.
*/
private String compressableMimeTypes = "text/html,text/xml,text/plain"; public int getMaxThreads() {
return this.maxThreads;
} public void setMaxThreads(int maxThreads) {
this.maxThreads = maxThreads;
} public int getMaxHttpHeaderSize() {
return this.maxHttpHeaderSize;
} public void setMaxHttpHeaderSize(int maxHttpHeaderSize) {
this.maxHttpHeaderSize = maxHttpHeaderSize;
} public boolean getAccessLogEnabled() {
return this.accessLogEnabled;
} public void setAccessLogEnabled(boolean accessLogEnabled) {
this.accessLogEnabled = accessLogEnabled;
} public int getBackgroundProcessorDelay() {
return this.backgroundProcessorDelay;
} public void setBackgroundProcessorDelay(int backgroundProcessorDelay) {
this.backgroundProcessorDelay = backgroundProcessorDelay;
} public File getBasedir() {
return this.basedir;
} public void setBasedir(File basedir) {
this.basedir = basedir;
} public String getAccessLogPattern() {
return this.accessLogPattern;
} public void setAccessLogPattern(String accessLogPattern) {
this.accessLogPattern = accessLogPattern;
} public String getCompressableMimeTypes() {
return this.compressableMimeTypes;
} public void setCompressableMimeTypes(String compressableMimeTypes) {
this.compressableMimeTypes = compressableMimeTypes;
} public String getCompression() {
return this.compression;
} public void setCompression(String compression) {
this.compression = compression;
} public String getInternalProxies() {
return this.internalProxies;
} public void setInternalProxies(String internalProxies) {
this.internalProxies = internalProxies;
} public String getProtocolHeader() {
return this.protocolHeader;
} public void setProtocolHeader(String protocolHeader) {
this.protocolHeader = protocolHeader;
} public String getPortHeader() {
return this.portHeader;
} public void setPortHeader(String portHeader) {
this.portHeader = portHeader;
} public String getRemoteIpHeader() {
return this.remoteIpHeader;
} public void setRemoteIpHeader(String remoteIpHeader) {
this.remoteIpHeader = remoteIpHeader;
} public String getUriEncoding() {
return this.uriEncoding;
} public void setUriEncoding(String uriEncoding) {
this.uriEncoding = uriEncoding;
} void customizeTomcat(TomcatEmbeddedServletContainerFactory factory) {
if (getBasedir() != null) {
factory.setBaseDirectory(getBasedir());
}
customizeBackgroundProcessorDelay(factory);
customizeHeaders(factory);
if (this.maxThreads > 0) {
customizeMaxThreads(factory);
}
if (this.maxHttpHeaderSize > 0) {
customizeMaxHttpHeaderSize(factory);
}
customizeCompression(factory);
if (this.accessLogEnabled) {
customizeAccessLog(factory);
}
if (getUriEncoding() != null) {
factory.setUriEncoding(getUriEncoding());
}
} private void customizeBackgroundProcessorDelay(
TomcatEmbeddedServletContainerFactory factory) {
factory.addContextCustomizers(new TomcatContextCustomizer() { @Override
public void customize(Context context) {
context.setBackgroundProcessorDelay(Tomcat.this.backgroundProcessorDelay);
} });
} private void customizeHeaders(TomcatEmbeddedServletContainerFactory factory) {
String remoteIpHeader = getRemoteIpHeader();
String protocolHeader = getProtocolHeader();
if (StringUtils.hasText(remoteIpHeader)
|| StringUtils.hasText(protocolHeader)) {
RemoteIpValve valve = new RemoteIpValve();
valve.setRemoteIpHeader(remoteIpHeader);
valve.setProtocolHeader(protocolHeader);
valve.setInternalProxies(getInternalProxies());
valve.setPortHeader(getPortHeader());
factory.addContextValves(valve);
}
} @SuppressWarnings("rawtypes")
private void customizeMaxThreads(TomcatEmbeddedServletContainerFactory factory) {
factory.addConnectorCustomizers(new TomcatConnectorCustomizer() {
@Override
public void customize(Connector connector) { ProtocolHandler handler = connector.getProtocolHandler();
if (handler instanceof AbstractProtocol) {
AbstractProtocol protocol = (AbstractProtocol) handler;
protocol.setMaxThreads(Tomcat.this.maxThreads);
} }
});
} @SuppressWarnings("rawtypes")
private void customizeMaxHttpHeaderSize(
TomcatEmbeddedServletContainerFactory factory) {
factory.addConnectorCustomizers(new TomcatConnectorCustomizer() { @Override
public void customize(Connector connector) {
ProtocolHandler handler = connector.getProtocolHandler();
if (handler instanceof AbstractHttp11Protocol) {
AbstractHttp11Protocol protocol = (AbstractHttp11Protocol) handler;
protocol.setMaxHttpHeaderSize(Tomcat.this.maxHttpHeaderSize);
}
} });
} private void customizeCompression(TomcatEmbeddedServletContainerFactory factory) {
factory.addConnectorCustomizers(new TomcatConnectorCustomizer() { @Override
public void customize(Connector connector) {
ProtocolHandler handler = connector.getProtocolHandler();
if (handler instanceof AbstractHttp11Protocol) {
@SuppressWarnings("rawtypes")
AbstractHttp11Protocol protocol = (AbstractHttp11Protocol) handler;
protocol.setCompression(coerceCompression(Tomcat.this.compression));
protocol.setCompressableMimeTypes(Tomcat.this.compressableMimeTypes);
}
} private String coerceCompression(String compression) {
if ("true".equalsIgnoreCase(compression)) {
return "on";
}
if ("false".equalsIgnoreCase(compression)) {
return "off";
}
return compression;
} });
} private void customizeAccessLog(TomcatEmbeddedServletContainerFactory factory) {
AccessLogValve valve = new AccessLogValve();
String accessLogPattern = getAccessLogPattern();
valve.setPattern(accessLogPattern == null ? "common" : accessLogPattern);
valve.setSuffix(".log");
factory.addContextValves(valve);
} } public static class Undertow { /**
* Size of each buffer in bytes.
*/
private Integer bufferSize; /**
* Number of buffer per region.
*/
private Integer buffersPerRegion; /**
* Number of I/O threads to create for the worker.
*/
private Integer ioThreads; /**
* Number of worker threads.
*/
private Integer workerThreads; /**
* Allocate buffers outside the Java heap.
*/
private Boolean directBuffers; /**
* Format pattern for access logs.
*/
private String accessLogPattern = "common"; /**
* Enable access log.
*/
private boolean accessLogEnabled = false; /**
* Undertow access log directory.
*/
private File accessLogDir = new File("logs"); public Integer getBufferSize() {
return this.bufferSize;
} public void setBufferSize(Integer bufferSize) {
this.bufferSize = bufferSize;
} public Integer getBuffersPerRegion() {
return this.buffersPerRegion;
} public void setBuffersPerRegion(Integer buffersPerRegion) {
this.buffersPerRegion = buffersPerRegion;
} public Integer getIoThreads() {
return this.ioThreads;
} public void setIoThreads(Integer ioThreads) {
this.ioThreads = ioThreads;
} public Integer getWorkerThreads() {
return this.workerThreads;
} public void setWorkerThreads(Integer workerThreads) {
this.workerThreads = workerThreads;
} public Boolean getDirectBuffers() {
return this.directBuffers;
} public void setDirectBuffers(Boolean directBuffers) {
this.directBuffers = directBuffers;
} public String getAccessLogPattern() {
return this.accessLogPattern;
} public void setAccessLogPattern(String accessLogPattern) {
this.accessLogPattern = accessLogPattern;
} public boolean isAccessLogEnabled() {
return this.accessLogEnabled;
} public void setAccessLogEnabled(boolean accessLogEnabled) {
this.accessLogEnabled = accessLogEnabled;
} public File getAccessLogDir() {
return this.accessLogDir;
} public void setAccessLogDir(File accessLogDir) {
this.accessLogDir = accessLogDir;
} void customizeUndertow(UndertowEmbeddedServletContainerFactory factory) {
factory.setBufferSize(this.bufferSize);
factory.setBuffersPerRegion(this.buffersPerRegion);
factory.setIoThreads(this.ioThreads);
factory.setWorkerThreads(this.workerThreads);
factory.setDirectBuffers(this.directBuffers);
factory.setAccessLogDirectory(this.accessLogDir);
factory.setAccessLogPattern(this.accessLogPattern);
factory.setAccessLogEnabled(this.accessLogEnabled);
} } }

ServerProperties的更多相关文章

  1. Spring Boot

    Spring Boot是由Pivotal团队提供的全新框架,其设计目的是用来简化新Spring应用的初始搭建以及开发过程.该框架使用了特定的方式来进行配置,从而使开发人员不再需要定义样板化的配置.通过 ...

  2. 第一个Spring Boot Web程序

    需要的环境和工具: 1.Eclipse2.Java环境(JDK 1.7或以上版本)3.Maven 3.0+(Eclipse已经内置了) 写个Hello Spring: 1.新建一个Maven项目,项目 ...

  3. SpringBoot Demo

    Spring Boot,微框架,确实不错,很方便. 相关网站链接: http://www.tuicool.com/articles/veUjQba https://www.gitbook.com/bo ...

  4. Spring boot配置文件 application.properties

    http://www.tuicool.com/articles/veUjQba 本文记录Spring Boot application.propertis配置文件的相关通用属性 # ========= ...

  5. 004_kafka_安装运行

    1.下载和安装 目前kafka的稳定版本为0.10.0.0 下载地址:http://kafka.apache.org/downloads.html 下载后解压缩安装包到系统即可完成安装 > ta ...

  6. 深入学习微框架:Spring Boot(转)

    转:http://www.infoq.com/cn/articles/microframeworks1-spring-boot/ 相关参考: https://spring.io/guides/gs/s ...

  7. SpringCloud+Consul 服务注册与服务发现

    SpringCloud+Consul 服务注册与服务发现 1. 服务注册: 在Spring.factories有一段: # Discovery Client Configuration org.spr ...

  8. 玩转spring boot——properties配置

    前言 在以往的java开发中,程序员最怕大量的配置,是因为配置一多就不好统一管理,经常出现找不到配置的情况.而项目中,从开发测试环境到生产环境,往往需要切换不同的配置,如测试数据库连接换成生产数据库连 ...

  9. 深入学习微框架:Spring Boot - NO

    http://blog.csdn.net/hengyunabc/article/details/50120001 Our primary goals are: Provide a radically ...

随机推荐

  1. 10招搞定web设计风格指南

    From:http://www.ui.cn/detail/27579.html 今时今日,网站的创建正变得越来越复杂,而且一般都不是一个人就能干的了的.在创建网站过程中,我们需要保证设计前后一致,并符 ...

  2. OpenstackHigh-level-service

    1,yum -y install openstack-cinder;

  3. IT人员应该怎么跳槽

    中国的程序员只有两个状态,刚跳槽和准备跳槽.   中国IT行业的快速发展对IT从业人员的需求不断扩大,记得08年刚毕业的时候,在帝都找一个3k的工作都让我特别满足,现在仅能写出”hello world ...

  4. mysql用户和权限管理

    用户和权限管理 Information about account privileges is stored in the user, db, host, tables_priv, columns_p ...

  5. iOS 推送证书制作 (JAVA/PHP)

    // aps_development.cer 转化成pem openssl x509 -in aps_development.cer -inform der -out PushChatCert.pem ...

  6. Android声明和使用权限

    Android定义了一种权限方案来保护设备上的资源和功能.例如,在默认情况下,应用程序无法访问联系人列表.拨打电话等.下面就以拨打电话为例介绍一下系统对权限的要求.一般在我们的应用中,如果要用到拨打电 ...

  7. 使用cx_Freeze 将python3代码打包成.exe程序

    在这里分享一下如何在py3下使用cx_Freeze打包pyqt5的程序 首先吐槽下,深深鄙视一下百度,各种百度各种没有,之前我在py2.7下使用pyqt4开发过一个小软件,用的是py2exe进行打包的 ...

  8. PHP性能优化学习笔记--语言级性能优化--来自慕课网Pangee http://www.imooc.com/learn/205

    使用ab进行压力测试 ab -n行数 -c并发数 url 重点关注下面两点: 1.Request per secend : 每秒可接收的请求数 2.Time per request : 每次请求所耗费 ...

  9. PHP冒泡排序,选择排序,插入排序

    1  冒泡排序是两个元素相互比较,找到最小值,然后冒泡到最后,代码如下:

  10. Unity目录结构

    http://www.cnblogs.com/liudq/p/5540051.htmlUnity中有几个默认目录 Unity5.x Resources 项目中默认的资源路径,会直接打包到游戏包中.即使 ...