SpringBoot 2.0 系列007 --WEB容器详解

本文详细介绍了SpringBoot 2.0中关于WEB容器的配置,包括通用服务配置如端口、SSL、压缩等,以及Tomcat、Jetty、Undertow三大服务器的整合使用和配置。此外,还提供了相关配置的使用方式和源码参考。
摘要由CSDN通过智能技术生成

SpringBoot 2.0 系列007 --WEB容器详解

我们知道java常用的两大容器tomcat和jetty,其中SB默认内嵌了tomcat容器。那么SB都支持什么属性呢?

  • 参阅ServerProperties.java

基本是通用的服务器配置,以及error、Compression、Http2、Servlet、Tomcat、Jetty、Undertow等配置。

可用配置

1. 通用服务配置

port

服务器端口号

  • 使用方式

server.port=8080,默認端口号8080

address

服务绑定的网络地址

  • 使用方式

server.address=127.0.0.1

useForwardHeaders

请求是否允许X-Forwarded-*

  • 使用方式

server.use-forward-headers=false

serverHeader

服务响应头信息

  • 使用方式

server.server-header=xxxx

maxHttpHeaderSize

最大头信息大小

  • 使用方式

server.max-http-header-size=0

connectionTimeout

连接超时时间

  • 使用方式

server.connection-timeout=-1

2. ssl

主要是ssl相关配置。具体参阅 org.springframework.boot.web.server.Ssl类

  • 使用方式

server.ssl.xxx=xxx

server.ssl.ciphers= # Supported SSL ciphers.
server.ssl.client-auth= # Whether client authentication is wanted ("want") or needed ("need"). Requires a trust store.
server.ssl.enabled= # Enable SSL support.
server.ssl.enabled-protocols= # Enabled SSL protocols.
server.ssl.key-alias= # Alias that identifies the key in the key store.
server.ssl.key-password= # Password used to access the key in the key store.
server.ssl.key-store= # Path to the key store that holds the SSL certificate (typically a jks file).
server.ssl.key-store-password= # Password used to access the key store.
server.ssl.key-store-provider= # Provider for the key store.
server.ssl.key-store-type= # Type of the key store.
server.ssl.protocol=TLS # SSL protocol to use.
server.ssl.trust-store= # Trust store that holds SSL certificates.
server.ssl.trust-store-password= # Password used to access the trust store.
server.ssl.trust-store-provider= # Provider for the trust store.
server.ssl.trust-store-type= # Type of the trust store.
public class Ssl {
    

	/**
	 * Whether to enable SSL support.
	 */
	private boolean enabled = true;

	/**
	 * Whether client authentication is wanted ("want") or needed ("need"). Requires a
	 * trust store.
	 */
	private ClientAuth clientAuth;

	/**
	 * Supported SSL ciphers.
	 */
	private String[] ciphers;

	/**
	 * Enabled SSL protocols.
	 */
	private String[] enabledProtocols;

	/**
	 * Alias that identifies the key in the key store.
	 */
	private String keyAlias;

	/**
	 * Password used to access the key in the key store.
	 */
	private String keyPassword;

	/**
	 * Path to the key store that holds the SSL certificate (typically a jks file).
	 */
	private String keyStore;

	/**
	 * Password used to access the key store.
	 */
	private String keyStorePassword;

	/**
	 * Type of the key store.
	 */
	private String keyStoreType;

	/**
	 * Provider for the key store.
	 */
	private String keyStoreProvider;

	/**
	 * Trust store that holds SSL certificates.
	 */
	private String trustStore;

	/**
	 * Password used to access the trust store.
	 */
	private String trustStorePassword;

	/**
	 * Type of the trust store.
	 */
	private String trustStoreType;

	/**
	 * Provider for the trust store.
	 */
	private String trustStoreProvider;

	/**
	 * SSL protocol to use.
	 */
	private String protocol = "TLS";

	public boolean isEnabled() {
    
		return this.enabled;
	}

	public void setEnabled(boolean enabled) {
    
		this.enabled = enabled;
	}

	public ClientAuth getClientAuth() {
    
		return this.clientAuth;
	}

	public void setClientAuth(ClientAuth clientAuth) {
    
		this.clientAuth = clientAuth;
	}

	public String[] getCiphers() {
    
		return this.ciphers;
	}

	public void setCiphers(String[] ciphers) {
    
		this.ciphers = ciphers;
	}

	public String getKeyAlias() {
    
		return this.keyAlias;
	}

	public void setKeyAlias(String keyAlias) {
    
		this.keyAlias = keyAlias;
	}

	public String getKeyPassword() {
    
		return this.keyPassword;
	}

	public void setKeyPassword(String keyPassword) {
    
		this.keyPassword = keyPassword;
	}

	public String getKeyStore() {
    
		return this.keyStore;
	}

	public void setKeyStore(String keyStore) {
    
		this.keyStore = keyStore;
	}

	public String getKeyStorePassword() {
    
		return this.keyStorePassword;
	}

	public void setKeyStorePassword(String keyStorePassword) {
    
		this.keyStorePassword = keyStorePassword;
	}

	public String getKeyStoreType() {
    
		return this.keyStoreType;
	}

	public void setKeyStoreType(String keyStoreType) {
    
		this.keyStoreType = keyStoreType;
	}

	public String getKeyStoreProvider() {
    
		return this.keyStoreProvider;
	}

	public void setKeyStoreProvider(String keyStoreProvider) {
    
		this.keyStoreProvider = keyStoreProvider;
	}

	public String[] getEnabledProtocols() {
    
		return this.enabledProtocols;
	}

	public void setEnabledProtocols(String[] enabledProtocols) {
    
		this.enabledProtocols = enabledProtocols;
	}

	public String getTrustStore() {
    
		return this.trustStore;
	}

	public void setTrustStore(String trustStore) {
    
		this.trustStore = trustStore;
	}

	public String getTrustStorePassword() {
    
		return this.trustStorePassword;
	}

	public void setTrustStorePassword(String trustStorePassword) {
    
		this.trustStorePassword = trustStorePassword;
	}

	public String getTrustStoreType() {
    
		return this.trustStoreType;
	}

	public void setTrustStoreType(String trustStoreType) {
    
		this.trustStoreType = trustStoreType;
	}

	public String getTrustStoreProvider() {
    
		return this.trustStoreProvider;
	}

	public void setTrustStoreProvider(String trustStoreProvider) {
    
		this.trustStoreProvider = trustStoreProvider;
	}

	public String getProtocol() {
    
		return this.protocol;
	}

	public void setProtocol(String protocol) {
    
		this.protocol = protocol;
	}

	/**
	 * Client authentication types.
	 */
	public enum ClientAuth {
    

		/**
		 * Client authentication is wanted but not mandatory.
		 */
		WANT,

		/**
		 * Client authentication is needed and mandatory.
		 */
		NEED

	}

}

3. compression

简单的压缩配置,具体参阅org.springframework.boot.web.server.Compression

  • 使用方式

server.compression.xx=xx

server.compression.enabled=false # Whether response compression is enabled.
server.compression.excluded-user-agents= # List of user-agents to exclude from compression.
server.compression.mime-types=text/html,text/xml,text/plain,text/css,text/javascript,application/javascript # Comma-separated list of MIME types that should be compressed.
server.compression.min-response-size=2048 # Minimum "Content-Length" value that is required for compression to be performed.

  • 附源码
public class Compression {
    

	/**
	 * Whether response compression is enabled.
	 */
	private boolean enabled = false;

	/**
	 * Comma-separated list of MIME types that should be compressed.
	 */
	private String[] mimeTypes = new String[] {
     "text/html", "text/xml", "text/plain",
			"text/css", "text/javascript", "application/javascript", "application/json",
			"application/xml" };

	/**
	 * Comma-separated list of user agents for which responses should not be compressed.
	 */
	private String[] excludedUserAgents = null;

	/**
	 * Minimum "Content-Length" value that is required for compression to be performed.
	 */
	private int minResponseSize = 2048;

	public boolean getEnabled() {
    
		return this.enabled;
	}

	public void setEnabled(boolean enabled) {
    
		this.enabled = enabled;
	}

	public String[] getMimeTypes() {
    
		return this.mimeTypes;
	}

	public void setMimeTypes(
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值