1. 程式人生 > >springboot自定義配置選項檢視技巧

springboot自定義配置選項檢視技巧

在使用springboot的時候,由於它的自動配置的存在,一開始很容易上手進行應用開發,但是等需要進行深度自定義配置的時候,很多人蒙圈,哪些內容可以自定義配置,配置引數是什麼等等問題接踵而來,剛好我有個任務要進行springboot tomcat有那些配置引數可以配置的說明,所以就借這個機會告訴大家怎麼檢視某一個模組的配置引數有哪些。

首先,springboot的大部分自動配置類都在一個叫spring-boot-autoconfigure-X.x.x.jar包裡,如下所示:

tomcat的配置在org.springframework.boot.autoconfigure.web包裡的ServerProperties

,它包括tomcatjettyundertow的配置都在裡面,當然有公用的和具體伺服器獨立的配置,我們先看下它的類定義:

 

@ConfigurationPropertiesspring 4.x新特性,通過讀取配置檔案資料來注入我們的實體屬性,如ServerProperties就是讀取配置檔案裡server開頭的配置選項來進行注入,比如我們在配置檔案裡配置了 server.port = 1000,則ServerPropertiesport埠就是1000;ServerPropertis的屬性就整個應用的web容器的公用配置選項,我們可以看出有哪些。

接下來看下tomcat的配置有哪些,在同一個類裡,我們找到

tomcat的類定義,如下圖所示:

從上面tomcat定義的屬性就可以看出,我們可以配置哪些熟悉,包括我們現在專案進行配置的accesslog配置,我點進Accesslog的定義,就知道怎麼在springboot配置檔案自定義配置accesslog,如下圖:

如果我們要配置accesslogenabled屬性,只需要在application.properties檔案裡定義

Server.tomcat.accesslog.enabled= true;

Tomcat的所有配置選項如下:

server. Port = xxxx

server. Address =

server. contextPath =

server. displayName =

server. servletPath =

server. contextParameters =

server. useForwardHeaders =

server. serverHeader =

server. maxHttpHeaderSize =

server. maxHttpPostSize =

server. connectionTimeout =

server. session.timeout =

server. session.trackingModes =

server. session.persistent =

server.session.storeDir =

server.cookie. name =

server.cookie. domain =

server.cookie. path =

server.cookie. comment =

server.cookie. httpOnly =

server.cookie. secure =

server.cookie. maxAge =

server. ssl. Enabled =

server.ssl. clientAuth =

server.ssl. ciphers =

server.ssl. enabledProtocols =

server.ssl. keyAlias =

server.ssl. keyPassword =

server.ssl. keyStore =

server.ssl. keyStorePassword =

server.ssl. keyStoreType =

server.ssl. keyStoreProvider =

server.ssl. trustStore =

server.ssl. trustStorePassword =

server.ssl. trustStoreType =

server.ssl. trustStoreProvider =

server.ssl. protocol =

server.compression. enabled =

server.compression.mimeTypes =

server.compression.excludedUserAgents =

server.compression.minResponseSize =

server. jspServlet. className =

server.jspServlet. initParameters =

server.jspServlet.registered =

server.tomcat.accesslog.enabled =

server.tomcat.accesslog.pattern =

server.tomcat.accesslog.directory =

server.tomcat.accesslog.prefix =

server.tomcat.accesslog.suffix =

server.tomcat.accesslog.rotate =

server.tomcat.accesslog.renameOnRotate =

server.tomcat.accesslog.requestAttributesEnabled=

server.tomcat.accesslog.buffered =

server.tomcat.internalProxies =

server.tomcat.protocolHeader =

server.tomcat.protocolHeaderHttpsValue =

server.tomcat.portHeader =

server.tomcat.remoteIpHeader=

server.tomcat.basedir =

server.tomcat.backgroundProcessorDelay =

server.tomcat.maxThreads =

server.tomcat.minSpareThreads =

server.tomcat.maxHttpPostSize =

server.tomcat.maxHttpHeaderSize =

server.tomcat.redirectContextRoot =

server.tomcat.uriEncoding =

server.tomcat.maxConnections =

server.tomcat.additionalTldSkipPatterns =