天天看點

【Spring Boot學習總結】6.SpringBoot全局配置檔案

上一篇我們總結了SpringBoot的核心注解以及一些簡單的配置,本篇我們來了解SpringBoot的全局配置檔案。

Spring Boot項目使用一個全局配置檔案application.properties或者是application.yml,在resource目錄下或者類路徑下的/config下、一般開發中我們放置在resource下。

我們下面就在之前的測試工程中添加一個全局配置檔案。打開工程,在resource檔案夾下建立一個名為“application.properties”的檔案:

【Spring Boot學習總結】6.SpringBoot全局配置檔案

記得我們建立Spring Boot工程的時候,内置的Tomcat預設端口為8080,有時候我們需要重新制定端口,使用“server.port”就可以制定内置Tomcat容器的端口:

server.port=8088

我們這裡将端口改為了8088,重新開機項目,發現已經改變:

【Spring Boot學習總結】6.SpringBoot全局配置檔案

通路服務也是在8088端口:

【Spring Boot學習總結】6.SpringBoot全局配置檔案

然後我們也可以修改Spring MVC的DispatchServlet的響應規則,預設是比對所有請求路徑的,這裡我們改為所有請求以“html”結尾才被響應:

server.servlet-path=*.html

我們依然通路原來的位址,發現找不到資訊:

【Spring Boot學習總結】6.SpringBoot全局配置檔案

帶有html字尾就可以正常響應:

【Spring Boot學習總結】6.SpringBoot全局配置檔案

對于全局變量的配置,Spring Boot的官方給了我們一個比較完整的配置大全:

application.properties(下載下傳超連結:https://download.csdn.net/download/u013517797/10613303)

大家可以進行配置參考,但是注釋是純英文的,需要一些英文功底。

下面是我總結的一些常見的、重要的配置,後面以中文進行解釋,友善大家參考:

(1)mvc相關的一些配置

mvc

spring.mvc.async.request-timeout設定async請求的逾時時間,以毫秒為機關,如果沒有設定的話,以具體實作的逾時時間為準,比如tomcat的servlet3的話是10秒.

spring.mvc.date-format設定日期的格式,比如dd/MM/yyyy.

spring.mvc.favicon.enabled是否支援favicon.ico,預設為: true

spring.mvc.ignore-default-model-on-redirect在重定向時是否忽略預設model的内容,預設為true

spring.mvc.locale指定使用的Locale.

spring.mvc.message-codes-resolver-format指定message codes的格式化政策(PREFIX_ERROR_CODE,POSTFIX_ERROR_CODE).

spring.mvc.view.prefix指定mvc視圖的字首.

spring.mvc.view.suffix指定mvc視圖的字尾.

messages

spring.messages.basename指定message的basename,多個以逗号分隔,如果不加包名的話,預設從classpath路徑開始,預設: messages

spring.messages.cache-seconds設定加載的資源檔案緩存失效時間,-1的話為永不過期,預設為-1

spring.messages.encoding設定Message bundles的編碼,預設: UTF-8

mobile

spring.mobile.devicedelegatingviewresolver.enable-fallback是否支援fallback的解決方案,預設false

spring.mobile.devicedelegatingviewresolver.enabled是否開始device view resolver,預設為: false

spring.mobile.devicedelegatingviewresolver.mobile-prefix設定mobile端視圖的字首,預設為:mobile/

spring.mobile.devicedelegatingviewresolver.mobile-suffix設定mobile視圖的字尾

spring.mobile.devicedelegatingviewresolver.normal-prefix設定普通裝置的視圖字首

spring.mobile.devicedelegatingviewresolver.normal-suffix設定普通裝置視圖的字尾

spring.mobile.devicedelegatingviewresolver.tablet-prefix設定平闆裝置視圖字首,預設:tablet/

spring.mobile.devicedelegatingviewresolver.tablet-suffix設定平闆裝置視圖字尾.

spring.mobile.sitepreference.enabled是否啟用SitePreferenceHandler,預設為: true

view

spring.view.prefix設定mvc視圖的字首.

spring.view.suffix設定mvc視圖的字尾.

resource

spring.resources.add-mappings是否開啟預設的資源處理,預設為true

spring.resources.cache-period設定資源的緩存時效,以秒為機關.

spring.resources.chain.cache是否開啟緩存,預設為: true

spring.resources.chain.enabled是否開啟資源 handling chain,預設為false

spring.resources.chain.html-application-cache是否開啟h5應用的cache manifest重寫,預設為: false

spring.resources.chain.strategy.content.enabled是否開啟内容版本政策,預設為false

spring.resources.chain.strategy.content.paths指定要應用的版本的路徑,多個以逗号分隔,預設為:[/**]

spring.resources.chain.strategy.fixed.enabled是否開啟固定的版本政策,預設為false

spring.resources.chain.strategy.fixed.paths指定要應用版本政策的路徑,多個以逗号分隔

spring.resources.chain.strategy.fixed.version指定版本政策使用的版本号

spring.resources.static-locations指定靜态資源路徑,預設為classpath:[/META-INF/resources/,/resources/, /static/, /public/]以及context:/

multipart

multipart.enabled是否開啟檔案上傳支援,預設為true

multipart.file-size-threshold設定檔案寫入磁盤的門檻值,機關為MB或KB,預設為0

multipart.location指定檔案上傳路徑.

multipart.max-file-size指定檔案大小最大值,預設1MB

multipart.max-request-size指定每次請求的最大值,預設為10MB

freemarker

spring.freemarker.allow-request-override指定HttpServletRequest的屬性是否可以覆寫controller的model的同名項

spring.freemarker.allow-session-override指定HttpSession的屬性是否可以覆寫controller的model的同名項

spring.freemarker.cache是否開啟template caching.

spring.freemarker.charset設定Template的編碼.

spring.freemarker.check-template-location是否檢查templates路徑是否存在.

spring.freemarker.content-type設定Content-Type.

spring.freemarker.enabled是否允許mvc使用freemarker.

spring.freemarker.expose-request-attributes設定所有request的屬性在merge到模闆的時候,是否要都添加到model中.

spring.freemarker.expose-session-attributes設定所有HttpSession的屬性在merge到模闆的時候,是否要都添加到model中.

spring.freemarker.expose-spring-macro-helpers設定是否以springMacroRequestContext的形式暴露RequestContext給Spring’s macro library使用

spring.freemarker.prefer-file-system-access是否優先從檔案系統加載template,以支援熱加載,預設為true

spring.freemarker.prefix設定freemarker模闆的字首.

spring.freemarker.request-context-attribute指定RequestContext屬性的名.

spring.freemarker.settings設定FreeMarker keys.

spring.freemarker.suffix設定模闆的字尾.

spring.freemarker.template-loader-path設定模闆的加載路徑,多個以逗号分隔,預設: ["classpath:/templates/"]

spring.freemarker.view-names指定使用模闆的視圖清單.

velocity

spring.velocity.allow-request-override指定HttpServletRequest的屬性是否可以覆寫controller的model的同名項

spring.velocity.allow-session-override指定HttpSession的屬性是否可以覆寫controller的model的同名項

spring.velocity.cache是否開啟模闆緩存

spring.velocity.charset設定模闆編碼

spring.velocity.check-template-location是否檢查模闆路徑是否存在.

spring.velocity.content-type設定ContentType的值

spring.velocity.date-tool-attribute設定暴露給velocity上下文使用的DateTool的名

spring.velocity.enabled設定是否允許mvc使用velocity

spring.velocity.expose-request-attributes是否在merge模闆的時候,将request屬性都添加到model中

spring.velocity.expose-session-attributes是否在merge模闆的時候,将HttpSession屬性都添加到model中

spring.velocity.expose-spring-macro-helpers設定是否以springMacroRequestContext的名來暴露RequestContext給Spring’s macro類庫使用

spring.velocity.number-tool-attribute設定暴露給velocity上下文的NumberTool的名

spring.velocity.prefer-file-system-access是否優先從檔案系統加載模闆以支援熱加載,預設為true

spring.velocity.prefix設定velocity模闆的字首.

spring.velocity.properties設定velocity的額外屬性.

spring.velocity.request-context-attribute設定RequestContext attribute的名.

spring.velocity.resource-loader-path設定模闆路徑,預設為: classpath:/templates/

spring.velocity.suffix設定velocity模闆的字尾.

spring.velocity.toolbox-config-location設定Velocity Toolbox配置檔案的路徑,比如 /WEB-INF/toolbox.xml.

spring.velocity.view-names設定需要解析的視圖名稱.

thymeleaf

spring.thymeleaf.cache是否開啟模闆緩存,預設true

spring.thymeleaf.check-template-location是否檢查模闆路徑是否存在,預設true

spring.thymeleaf.content-type指定Content-Type,預設為: text/html

spring.thymeleaf.enabled是否允許MVC使用Thymeleaf,預設為: true

spring.thymeleaf.encoding指定模闆的編碼,預設為: UTF-8

spring.thymeleaf.excluded-view-names指定不使用模闆的視圖名稱,多個以逗号分隔.

spring.thymeleaf.mode指定模闆的模式,具體檢視StandardTemplateModeHandlers,預設為: HTML5

spring.thymeleaf.prefix指定模闆的字首,預設為:classpath:/templates/

spring.thymeleaf.suffix指定模闆的字尾,預設為:.html

spring.thymeleaf.template-resolver-order指定模闆的解析順序,預設為第一個.

spring.thymeleaf.view-names指定使用模闆的視圖名,多個以逗号分隔.

mustcache

spring.mustache.cache是否Enable template caching.

spring.mustache.charset指定Template的編碼.

spring.mustache.check-template-location是否檢查預設的路徑是否存在.

spring.mustache.content-type指定Content-Type.

spring.mustache.enabled是否開啟mustcache的模闆支援.

spring.mustache.prefix指定模闆的字首,預設: classpath:/templates/

spring.mustache.suffix指定模闆的字尾,預設: .html

spring.mustache.view-names指定要使用模闆的視圖名.

groovy模闆

spring.groovy.template.allow-request-override指定HttpServletRequest的屬性是否可以覆寫controller的model的同名項

spring.groovy.template.allow-session-override指定HttpSession的屬性是否可以覆寫controller的model的同名項

spring.groovy.template.cache是否開啟模闆緩存.

spring.groovy.template.charset指定Template編碼.

spring.groovy.template.check-template-location是否檢查模闆的路徑是否存在.

spring.groovy.template.configuration.auto-escape是否在渲染模闆時自動排查model的變量,預設為: false

spring.groovy.template.configuration.auto-indent是否在渲染模闆時自動縮進,預設為false

spring.groovy.template.configuration.auto-indent-string如果自動縮進啟用的話,是使用SPACES還是TAB,預設為: SPACES

spring.groovy.template.configuration.auto-new-line渲染模闆時是否要輸出換行,預設為false

spring.groovy.template.configuration.base-template-class指定template base class.

spring.groovy.template.configuration.cache-templates是否要緩存模闆,預設為true

spring.groovy.template.configuration.declaration-encoding在寫入declaration header時使用的編碼

spring.groovy.template.configuration.expand-empty-elements

是使用<br/>這種形式,還是<br></br>這種展開模式,預設為: false)

spring.groovy.template.configuration.locale指定template locale.

spring.groovy.template.configuration.new-line-string當啟用自動換行時,換行的輸出,預設為系統的line.separator屬性的值

spring.groovy.template.configuration.resource-loader-path指定groovy的模闆路徑,預設為classpath:/templates/

spring.groovy.template.configuration.use-double-quotes指定屬性要使用雙引号還是單引号,預設為false

spring.groovy.template.content-type指定Content-Type.

spring.groovy.template.enabled是否開啟groovy模闆的支援.

spring.groovy.template.expose-request-attributes設定所有request的屬性在merge到模闆的時候,是否要都添加到model中.

spring.groovy.template.expose-session-attributes設定所有request的屬性在merge到模闆的時候,是否要都添加到model中.

spring.groovy.template.expose-spring-macro-helpers設定是否以springMacroRequestContext的形式暴露RequestContext給Spring’s macro library使用

spring.groovy.template.prefix指定模闆的字首.

spring.groovy.template.request-context-attribute指定RequestContext屬性的名.

spring.groovy.template.resource-loader-path指定模闆的路徑,預設為: classpath:/templates/

spring.groovy.template.suffix指定模闆的字尾

spring.groovy.template.view-names指定要使用模闆的視圖名稱.

http

spring.hateoas.apply-to-primary-object-mapper設定是否對object mapper也支援HATEOAS,預設為: true

spring.http.converters.preferred-json-mapper是否優先使用JSON mapper來轉換.

spring.http.encoding.charset指定http請求和相應的Charset,預設: UTF-8

spring.http.encoding.enabled是否開啟http的編碼支援,預設為true

spring.http.encoding.force是否強制對http請求和響應進行編碼,預設為true

json

spring.jackson.date-format指定日期格式,比如yyyy-MM-dd HH:mm:ss,或者具體的格式化類的全限定名

spring.jackson.deserialization是否開啟Jackson的反序列化

spring.jackson.generator是否開啟json的generators.

spring.jackson.joda-date-time-format指定Joda date/time的格式,比如yyyy-MM-dd HH:mm:ss). 如果沒有配置的話,dateformat會作為backup

spring.jackson.locale指定json使用的Locale.

spring.jackson.mapper是否開啟Jackson通用的特性.

spring.jackson.parser是否開啟jackson的parser特性.

spring.jackson.property-naming-strategy指定PropertyNamingStrategy (CAMEL_CASE_TO_LOWER_CASE_WITH_UNDERSCORES)或者指定PropertyNamingStrategy子類的全限定類名.

spring.jackson.serialization是否開啟jackson的序列化.

spring.jackson.serialization-inclusion指定序列化時屬性的inclusion方式,具體檢視JsonInclude.Include枚舉.

spring.jackson.time-zone指定日期格式化時區,比如America/Los_Angeles或者GMT+10.

jersey

spring.jersey.filter.order指定Jersey filter的order,預設為: 0

spring.jersey.init指定傳遞給Jersey的初始化參數.

spring.jersey.type指定Jersey的內建類型,可以是servlet或者filter.

(2)server伺服器相關的一些配置

server.address指定server綁定的位址

server.compression.enabled是否開啟壓縮,預設為false.

server.compression.excluded-user-agents指定不壓縮的user-agent,多個以逗号分隔,預設值為:text/html,text/xml,text/plain,text/css

server.compression.mime-types指定要壓縮的MIME type,多個以逗号分隔.

server.compression.min-response-size執行壓縮的門檻值,預設為2048

server.context-parameters.[param name]設定servlet context 參數

server.context-path設定應用的context-path.

server.display-name設定應用的展示名稱,預設: application

server.jsp-servlet.class-name設定編譯JSP用的servlet,預設: org.apache.jasper

.servlet.JspServlet)

server.jsp-servlet.init-parameters.[param name]設定JSP servlet 初始化參數.

server.jsp-servlet.registered設定JSP servlet是否注冊到内嵌的servlet容器,預設true

server.port設定http監聽端口

server.servlet-path設定dispatcher servlet的監聽路徑,預設為: /

cookie、session配置

server.session.cookie.comment指定session cookie的comment

server.session.cookie.domain指定session cookie的domain

server.session.cookie.http-only是否開啟HttpOnly.

server.session.cookie.max-age設定session cookie的最大age.

server.session.cookie.name設定Session cookie 的名稱.

server.session.cookie.path設定session cookie的路徑.

server.session.cookie.secure設定session cookie的“Secure” flag.

server.session.persistent重新開機時是否持久化session,預設false

server.session.timeoutsession的逾時時間

server.session.tracking-modes設定Session的追蹤模式(cookie, url, ssl).

ssl配置

server.ssl.ciphers是否支援SSL ciphers.

server.ssl.client-auth設定client authentication是wanted 還是 needed.

server.ssl.enabled是否開啟ssl,預設: true

server.ssl.key-alias設定key store中key的别名.

server.ssl.key-password通路key store中key的密碼.

server.ssl.key-store設定持有SSL certificate的key store的路徑,通常是一個.jks檔案.

server.ssl.key-store-password設定通路key store的密碼.

server.ssl.key-store-provider設定key store的提供者.

server.ssl.key-store-type設定key store的類型.

server.ssl.protocol使用的SSL協定,預設: TLS

server.ssl.trust-store持有SSL certificates的Trust store.

server.ssl.trust-store-password通路trust store的密碼.

server.ssl.trust-store-provider設定trust store的提供者.

server.ssl.trust-store-type指定trust store的類型.

tomcat

server.tomcat.access-log-enabled是否開啟access log ,預設: false)

server.tomcat.access-log-pattern設定access logs的格式,預設: common

server.tomcat.accesslog.directory設定log的目錄,預設: logs

server.tomcat.accesslog.enabled是否開啟access log,預設: false

server.tomcat.accesslog.pattern設定access logs的格式,預設: common

server.tomcat.accesslog.prefix設定Log 檔案的字首,預設: access_log

server.tomcat.accesslog.suffix設定Log 檔案的字尾,預設: .log

server.tomcat.background-processor-delay背景線程方法的Delay大小: 30

server.tomcat.basedir設定Tomcat的base 目錄,如果沒有指定則使用臨時目錄.

server.tomcat.internal-proxies設定信任的正規表達式,預設:“10\.\d{1,3}\.\d{1,3}\.\d{1,3}| 192\.168\.\d{1,3}\.\d{1,3}| 169\.254\.\d{1,3}\.\d{1,3}| 127\.\d{1,3}\.\d{1,3}\.\d{1,3}| 172\.1[6-9]{1}\.\d{1,3}\.\d{1,3}| 172\.2[0-9]{1}\.\d{1,3}\.\d{1,3}|172\.3[0-1]{1}\.\d{1,3}\.\d{1,3}”

server.tomcat.max-http-header-size設定http header的最小值,預設: 0

server.tomcat.max-threads設定tomcat的最大工作線程數,預設為: 0

server.tomcat.port-header設定http header使用的,用來覆寫原來port的value.

server.tomcat.protocol-header設定Header包含的協定,通常是 X-Forwarded-Proto,如果remoteIpHeader有值,則将設定為RemoteIpValve.

server.tomcat.protocol-header-https-value設定使用SSL的header的值,預設https.

server.tomcat.remote-ip-header設定remote IP的header,如果remoteIpHeader有值,則設定為RemoteIpValve

server.tomcat.uri-encoding設定URI的解碼字元集.

undertow

server.undertow.access-log-dir設定Undertow access log 的目錄,預設: logs

server.undertow.access-log-enabled是否開啟access log,預設: false

server.undertow.access-log-pattern設定access logs的格式,預設: common

server.undertow.accesslog.dir設定access log 的目錄.

server.undertow.buffer-size設定buffer的大小.

server.undertow.buffers-per-region設定每個region的buffer數

server.undertow.direct-buffers設定堆外記憶體

server.undertow.io-threads設定I/O線程數.

server.undertow.worker-threads設定工作線程數

(3)DataSource資料源相關配置

spring.dao.exceptiontranslation.enabled是否開啟PersistenceExceptionTranslationPostProcessor,預設為true

spring.datasource.abandon-when-percentage-full設定逾時被廢棄的連接配接占到多少比例時要被關閉或上報

spring.datasource.allow-pool-suspension使用Hikari pool時,是否允許連接配接池暫停,預設為: false

spring.datasource.alternate-username-allowed是否允許替代的使用者名.

spring.datasource.auto-commit指定updates是否自動送出.

spring.datasource.catalog指定預設的catalog.

spring.datasource.commit-on-return設定當連接配接被歸還時,是否要送出所有還未完成的事務

spring.datasource.connection-init-sql指定連接配接被建立,再被添加到連接配接池之前執行的sql.

spring.datasource.connection-init-sqls使用DBCP connection pool時,指定初始化時要執行的sql

spring.datasource.connection-properties.[key]在使用DBCP connection pool時指定要配置的屬性

spring.datasource.connection-test-query指定校驗連接配接合法性執行的sql語句

spring.datasource.connection-timeout指定連接配接的逾時時間,毫秒機關.

spring.datasource.continue-on-error在初始化資料庫時,遇到錯誤是否繼續,預設false

spring.datasource.data指定Data (DML)腳本

spring.datasource.data-source-class-name指定資料源的全限定名.

spring.datasource.data-source-jndi指定jndi的位址

spring.datasource.data-source-properties.[key]使用Hikari connection pool時,指定要設定的屬性

spring.datasource.db-properties使用Tomcat connection pool,指定要設定的屬性

spring.datasource.default-auto-commit是否自動送出.

spring.datasource.default-catalog指定連接配接預設的catalog.

spring.datasource.default-read-only是否設定預設連接配接隻讀.

spring.datasource.default-transaction-isolation指定連接配接的事務的預設隔離級别.

spring.datasource.driver-class-name指定driver的類名,預設從jdbc url中自動探測.

spring.datasource.fair-queue是否采用FIFO傳回連接配接.

spring.datasource.health-check-properties.[key]使用Hikari connection pool時,在心跳檢查時傳遞的屬性

spring.datasource.idle-timeout指定連接配接多久沒被使用時,被設定為空閑,預設為10ms

spring.datasource.ignore-exception-on-pre-load當初始化連接配接池時,是否忽略異常.

spring.datasource.init-sql當連接配接建立時,執行的sql

spring.datasource.initial-size指定啟動連接配接池時,初始建立的連接配接數量

spring.datasource.initialization-fail-fast當建立連接配接池時,沒法建立指定最小連接配接數量是否抛異常

spring.datasource.initialize指定初始化資料源,是否用data.sql來初始化,預設: true

spring.datasource.isolate-internal-queries指定内部查詢是否要被隔離,預設為false

spring.datasource.jdbc-interceptors使用Tomcat connection pool時,指定jdbc攔截器,分号分隔

spring.datasource.jdbc-url指定JDBC URL.

spring.datasource.jmx-enabled是否開啟JMX,預設為: false

spring.datasource.jndi-name指定jndi的名稱.

spring.datasource.leak-detection-threshold使用Hikari connection pool時,多少毫秒檢測一次連接配接洩露.

spring.datasource.log-abandoned使用DBCP connection pool,是否追蹤廢棄statement或連接配接,預設為: false

spring.datasource.log-validation-errors當使用Tomcat connection pool是否列印校驗錯誤.

spring.datasource.login-timeout指定連接配接資料庫的逾時時間.

spring.datasource.max-active指定連接配接池中最大的活躍連接配接數.

spring.datasource.max-age指定連接配接池中連接配接的最大年齡

spring.datasource.max-idle指定連接配接池最大的空閑連接配接數量.

spring.datasource.max-lifetime指定連接配接池中連接配接的最大生存時間,毫秒機關.

spring.datasource.max-open-prepared-statements指定最大的打開的prepared statements數量.

spring.datasource.max-wait指定連接配接池等待連接配接傳回的最大等待時間,毫秒機關.

spring.datasource.maximum-pool-size指定連接配接池最大的連接配接數,包括使用中的和空閑的連接配接.

spring.datasource.min-evictable-idle-time-millis指定一個空閑連接配接最少空閑多久後可被清除.

spring.datasource.min-idle指定必須保持連接配接的最小值(For DBCP and Tomcat connection pools)

spring.datasource.minimum-idle指定連接配接維護的最小空閑連接配接數,當使用HikariCP時指定.

spring.datasource.name指定資料源名.

spring.datasource.num-tests-per-eviction-run指定運作每個idle object evictor線程時的對象數量

spring.datasource.password指定資料庫密碼.

spring.datasource.platform指定schema要使用的Platform(schema-${platform}.sql),預設為: all

spring.datasource.pool-name指定連接配接池名字.

spring.datasource.pool-prepared-statements指定是否池化statements.

spring.datasource.propagate-interrupt-state在等待連接配接時,如果線程被中斷,是否傳播中斷狀态.

spring.datasource.read-only當使用Hikari connection pool時,是否标記資料源隻讀

spring.datasource.register-mbeans指定Hikari connection pool是否注冊JMX MBeans.

spring.datasource.remove-abandoned指定當連接配接超過廢棄逾時時間時,是否立刻删除該連接配接.

spring.datasource.remove-abandoned-timeout指定連接配接應該被廢棄的時間.

spring.datasource.rollback-on-return在歸還連接配接時,是否復原等待中的事務.

spring.datasource.schema指定Schema (DDL)腳本.

spring.datasource.separator指定初始化腳本的語句分隔符,預設: ;

spring.datasource.sql-script-encoding指定SQL scripts編碼.

spring.datasource.suspect-timeout指定列印廢棄連接配接前的逾時時間.

spring.datasource.test-on-borrow當從連接配接池借用連接配接時,是否測試該連接配接.

spring.datasource.test-on-connect建立時,是否測試連接配接

spring.datasource.test-on-return在連接配接歸還到連接配接池時是否測試該連接配接.

spring.datasource.test-while-idle當連接配接空閑時,是否執行連接配接測試.

spring.datasource.time-between-eviction-runs-millis指定空閑連接配接檢查、廢棄連接配接清理、空閑連接配接池大小調整之間的操作時間間隔

spring.datasource.transaction-isolation指定事務隔離級别,使用Hikari connection pool時指定

spring.datasource.url指定JDBC URL.

spring.datasource.use-disposable-connection-facade是否對連接配接進行包裝,防止連接配接關閉之後被使用.

spring.datasource.use-equals比較方法名時是否使用String.equals()替換==.

spring.datasource.use-lock是否對連接配接操作加鎖

spring.datasource.username指定資料庫名.

spring.datasource.validation-interval指定多少ms執行一次連接配接校驗.

spring.datasource.validation-query指定擷取連接配接時連接配接校驗的sql查詢語句.

spring.datasource.validation-query-timeout指定連接配接校驗查詢的逾時時間.

spring.datasource.validation-timeout設定連接配接校驗的逾時時間,當使用Hikari connection pool時指定

spring.datasource.validator-class-name用來測試查詢的validator全限定名.

spring.datasource.xa.data-source-class-name指定資料源的全限定名.

spring.datasource.xa.properties指定傳遞給XA data source的屬性

JPA

spring.jpa.database指定目标資料庫.

spring.jpa.database-platform指定目标資料庫的類型.

spring.jpa.generate-ddl是否在啟動時初始化schema,預設為false

spring.jpa.hibernate.ddl-auto指定DDL mode (none, validate, update, create, create-drop). 當使用内嵌資料庫時,預設是create-drop,否則為none.

spring.jpa.hibernate.naming-strategy指定命名政策.

spring.jpa.open-in-view是否注冊OpenEntityManagerInViewInterceptor,綁定JPA EntityManager到請求線程中,預設為: true

spring.jpa.properties添加額外的屬性到JPA provider.

spring.jpa.show-sql是否開啟sql的log,預設為: false

jooq

spring.jooq.sql-dialect指定JOOQ使用的SQLDialect,比如POSTGRES.

h2

spring.h2.console.enabled是否開啟控制台,預設為false

spring.h2.console.path指定控制台路徑,預設為: /h2-console

JTA

spring.jta.allow-multiple-lrc是否允許 multiple LRC,預設為: false

spring.jta.asynchronous2-pc指定兩階段送出是否可以異步,預設為: false

spring.jta.background-recovery-interval指定多少分鐘跑一次recovery process,預設為: 1

spring.jta.background-recovery-interval-seconds指定多久跑一次recovery process,預設: 60

spring.jta.current-node-only-recovery是否過濾掉其他非本JVM的recovery,預設為: true

spring.jta.debug-zero-resource-transaction是否追蹤沒有使用指定資源的事務,預設為: false

spring.jta.default-transaction-timeout設定預設的事務逾時時間,預設為60

spring.jta.disable-jmx是否禁用jmx,預設為false

spring.jta.enabled是否開啟JTA support,預設為: true

spring.jta.exception-analyzer設定指定的異常分析類

spring.jta.filter-log-status使用Bitronix Transaction Manager時,是否寫mandatory logs,開啟的話,可以節省磁盤空間,但是調試會複雜寫,預設為false

spring.jta.force-batching-enabled使用Bitronix Transaction Manager時,是否批量寫磁盤,預設為true.

spring.jta.forced-write-enabled使用Bitronix Transaction Manager時,是否強制寫日志到磁盤,預設為true

spring.jta.graceful-shutdown-interval當使用Bitronix Transaction Manager,指定shutdown時等待事務結束的時間,超過則中斷,預設為60

spring.jta.jndi-transaction-synchronization-registry-name當使用Bitronix Transaction Manager時,在JNDI下得事務同步registry,預設為: java:comp/TransactionSynchronizationRegistry

spring.jta.jndi-user-transaction-name指定在JNDI使用Bitronix Transaction Manager的名稱,預設:java:comp/UserTransaction

spring.jta.journal當使用Bitronix Transaction Manager,指定The journal是否disk還是null還是一個類的全限定名,預設disk

spring.jta.log-dirTransaction logs directory.

spring.jta.log-part1-filename指定The journal fragment檔案1的名字,預設: btm1.tlog

spring.jta.log-part2-filename指定The journal fragment檔案2的名字,預設: btm2.tlog

spring.jta.max-log-size-in-mb指定journal fragments大小的最大值. 預設: 2M

spring.jta.resource-configuration-filename指定Bitronix Transaction Manager配置檔案名.

spring.jta.server-id指定Bitronix Transaction Manager執行個體的id.

spring.jta.skip-corrupted-logs是否忽略corrupted log files檔案,預設為false.

spring.jta.transaction-manager-id指定Transaction manager的唯一辨別.

spring.jta.warn-about-zero-resource-transaction當使用Bitronix Transaction Manager時,是否對沒有使用指定資源的事務進行警告,預設為: true

(4)cache緩存的相關配置

cache

spring.cache.cache-names指定要建立的緩存的名稱,逗号分隔(若該緩存實作支援的話)

spring.cache.ehcache.config指定初始化EhCache時使用的配置檔案的位置指定.

spring.cache.guava.spec指定建立緩存要使用的spec,具體詳見CacheBuilderSpec.

spring.cache.hazelcast.config指定初始化Hazelcast時的配置檔案位置

spring.cache.infinispan.config指定初始化Infinispan時的配置檔案位置.

spring.cache.jcache.config指定jcache的配置檔案.

spring.cache.jcache.provider指定CachingProvider實作類的全限定名.

spring.cache.type指定緩存類型

mongodb

spring.mongodb.embedded.features指定要開啟的特性,逗号分隔.

spring.mongodb.embedded.version指定要使用的版本,預設: 2.6.10

redis

spring.redis.database指定連接配接工廠使用的Database index,預設為: 0

spring.redis.host指定Redis server host,預設為: localhost

spring.redis.password指定Redis server的密碼

spring.redis.pool.max-active指定連接配接池最大的活躍連接配接數,-1表示無限,預設為8

spring.redis.pool.max-idle指定連接配接池最大的空閑連接配接數,-1表示無限,預設為8

spring.redis.pool.max-wait指定當連接配接池耗盡時,新擷取連接配接需要等待的最大時間,以毫秒機關,-1表示無限等待

spring.redis.pool.min-idle指定連接配接池中空閑連接配接的最小數量,預設為0

spring.redis.port指定redis服務端端口,預設: 6379

spring.redis.sentinel.master指定redis server的名稱

spring.redis.sentinel.nodes指定sentinel節點,逗号分隔,格式為host:port.

spring.redis.timeout指定連接配接逾時時間,毫秒機關,預設為0

springdata

spring.data.elasticsearch.cluster-name指定es叢集名稱,預設: elasticsearch

spring.data.elasticsearch.cluster-nodes指定es的叢集,逗号分隔,不指定的話,則啟動client node.

spring.data.elasticsearch.properties指定要配置的es屬性.

spring.data.elasticsearch.repositories.enabled是否開啟es存儲,預設為: true

spring.data.jpa.repositories.enabled是否開啟JPA支援,預設為: true

spring.data.mongodb.authentication-database指定鑒權的資料庫名

spring.data.mongodb.database指定mongodb資料庫名

spring.data.mongodb.field-naming-strategy指定要使用的FieldNamingStrategy.

spring.data.mongodb.grid-fs-database指定GridFS database的名稱.

spring.data.mongodb.host指定Mongo server host.

spring.data.mongodb.password指定Mongo server的密碼.

spring.data.mongodb.port指定Mongo server port.

spring.data.mongodb.repositories.enabled是否開啟mongodb存儲,預設為true

spring.data.mongodb.uri指定Mongo database URI.預設:mongodb://localhost/test

spring.data.mongodb.username指定登陸mongodb的使用者名.

spring.data.rest.base-path指定暴露資源的基準路徑.

spring.data.rest.default-page-size指定每頁的大小,預設為: 20

spring.data.rest.limit-param-name指定limit的參數名,預設為: size

spring.data.rest.max-page-size指定最大的頁數,預設為1000

spring.data.rest.page-param-name指定分頁的參數名,預設為: page

spring.data.rest.return-body-on-create當建立完實體之後,是否傳回body,預設為false

spring.data.rest.return-body-on-update在更新完實體後,是否傳回body,預設為false

spring.data.rest.sort-param-name指定排序使用的key,預設為: sort

spring.data.solr.host

指定Solr host,如果有指定了zk的host的話,則忽略。預設為: http://127.0.0.1:8983/solr

spring.data.solr.repositories.enabled是否開啟Solr repositories,預設為: true

spring.data.solr.zk-host指定zk的位址,格式為HOST:PORT.

(5)MQ消息中間件的相關配置

activemq

spring.activemq.broker-url指定ActiveMQ broker的URL,預設自動生成.

spring.activemq.in-memory是否是記憶體模式,預設為true.

spring.activemq.password指定broker的密碼.

spring.activemq.pooled是否建立PooledConnectionFactory,而非ConnectionFactory,預設false

spring.activemq.user指定broker的使用者.

artemis(HornetQ捐獻給apache後的版本)

spring.artemis.embedded.cluster-password指定叢集的密碼,預設是啟動時随機生成.

spring.artemis.embedded.data-directory指定Journal檔案的目錄.如果不開始持久化則不必要指定.

spring.artemis.embedded.enabled是否開啟内嵌模式,預設true

spring.artemis.embedded.persistent是否開啟persistent store,預設false.

spring.artemis.embedded.queues指定啟動時建立的隊列,多個用逗号分隔,預設: []

spring.artemis.embedded.server-id指定Server ID. 預設是一個自增的數字,從0開始.

spring.artemis.embedded.topics指定啟動時建立的topic,多個的話逗号分隔,預設: []

spring.artemis.host指定Artemis broker 的host. 預設: localhost

spring.artemis.mode指定Artemis 的部署模式, 預設為auto-detected(也可以為native or embedded).

spring.artemis.port指定Artemis broker 的端口,預設為: 61616

rabbitmq

spring.rabbitmq.addresses指定client連接配接到的server的位址,多個以逗号分隔.

spring.rabbitmq.dynamic是否建立AmqpAdmin bean. 預設為: true)

spring.rabbitmq.host指定RabbitMQ host.預設為: localhost)

spring.rabbitmq.listener.acknowledge-mode指定Acknowledge的模式.

spring.rabbitmq.listener.auto-startup是否在啟動時就啟動mq,預設: true)

spring.rabbitmq.listener.concurrency指定最小的消費者數量.

spring.rabbitmq.listener.max-concurrency指定最大的消費者數量.

spring.rabbitmq.listener.prefetch指定一個請求能處理多少個消息,如果有事務的話,必須大于等于transaction數量.

spring.rabbitmq.listener.transaction-size指定一個事務處理的消息數量,最好是小于等于prefetch的數量.

spring.rabbitmq.password指定broker的密碼.

spring.rabbitmq.port指定RabbitMQ 的端口,預設: 5672)

spring.rabbitmq.requested-heartbeat指定心跳逾時,0為不指定.

spring.rabbitmq.ssl.enabled是否開始SSL,預設: false)

spring.rabbitmq.ssl.key-store指定持有SSL certificate的key store的路徑

spring.rabbitmq.ssl.key-store-password指定通路key store的密碼.

spring.rabbitmq.ssl.trust-store指定持有SSL certificates的Trust store.

spring.rabbitmq.ssl.trust-store-password指定通路trust store的密碼.

spring.rabbitmq.username指定登陸broker的使用者名.

spring.rabbitmq.virtual-host指定連接配接到broker的Virtual host.

hornetq

spring.hornetq.embedded.cluster-password指定叢集的密碼,預設啟動時随機生成.

spring.hornetq.embedded.data-directory指定Journal file 的目錄. 如果不開啟持久化則不必指定.

spring.hornetq.embedded.enabled是否開啟内嵌模式,預設:true

spring.hornetq.embedded.persistent是否開啟persistent store,預設: false

spring.hornetq.embedded.queues指定啟動是建立的queue,多個以逗号分隔,預設: []

spring.hornetq.embedded.server-id指定Server ID. 預設使用自增數字,從0開始.

spring.hornetq.embedded.topics指定啟動時建立的topic,多個以逗号分隔,預設: []

spring.hornetq.host指定HornetQ broker 的host,預設: localhost

spring.hornetq.mode指定HornetQ 的部署模式,預設是auto-detected,也可以指定native 或者 embedded.

spring.hornetq.port指定HornetQ broker 端口,預設: 5445

jms

spring.jms.jndi-name指定Connection factory JNDI 名稱.

spring.jms.listener.acknowledge-mode指定ack模式,預設自動ack.

spring.jms.listener.auto-startup是否啟動時自動啟動jms,預設為: true

spring.jms.listener.concurrency指定最小的并發消費者數量.

spring.jms.listener.max-concurrency指定最大的并發消費者數量.

spring.jms.pub-sub-domain是否使用預設的destination type來支援 publish/subscribe,預設: false

(6)security安全機制的相關配置

spring security是springboot支援的權限控制系統。

security.basic.authorize-mode要使用權限控制模式.

security.basic.enabled是否開啟基本的鑒權,預設為true

security.basic.path需要鑒權的path,多個的話以逗号分隔,預設為[/**]

security.basic.realmHTTP basic realm 的名字,預設為Spring

security.enable-csrf是否開啟cross-site request forgery校驗,預設為false.

security.filter-orderSecurity filter chain的order,預設為0

security.headers.cache是否開啟http頭部的cache控制,預設為false.

security.headers.content-type是否開啟X-Content-Type-Options頭部,預設為false.

security.headers.frame是否開啟X-Frame-Options頭部,預設為false.

security.headers.hsts指定HTTP Strict Transport Security (HSTS)模式(none, domain, all).

security.headers.xss是否開啟cross-site scripting (XSS) 保護,預設為false.

security.ignored指定不鑒權的路徑,多個的話以逗号分隔.

security.oauth2.client.access-token-uri指定擷取access token的URI.

security.oauth2.client.access-token-validity-seconds指定access token失效時長.

security.oauth2.client.additional-information.[key]設定要添加的額外資訊.

security.oauth2.client.authentication-scheme指定傳輸不記名令牌(bearer token)的方式(form, header, none,query),預設為header

security.oauth2.client.authorities指定授予用戶端的權限.

security.oauth2.client.authorized-grant-types指定用戶端允許的grant types.

security.oauth2.client.auto-approve-scopes對用戶端自動授權的scope.

security.oauth2.client.client-authentication-scheme傳輸authentication credentials的方式(form, header, none, query),預設為header方式

security.oauth2.client.client-id指定OAuth2 client ID.

security.oauth2.client.client-secret指定OAuth2 client secret. 預設是一個随機的secret.

security.oauth2.client.grant-type指定擷取資源的access token的授權類型.

security.oauth2.client.id指定應用的client ID.

security.oauth2.client.pre-established-redirect-uri服務端pre-established的跳轉URI.

security.oauth2.client.refresh-token-validity-seconds指定refresh token的有效期.

security.oauth2.client.registered-redirect-uri指定用戶端跳轉URI,多個以逗号分隔.

security.oauth2.client.resource-ids指定用戶端相關的資源id,多個以逗号分隔.

security.oauth2.client.scopeclient的scope

security.oauth2.client.token-name指定token的名稱

security.oauth2.client.use-current-uri是否優先使用請求中URI,再使用pre-established的跳轉URI. 預設為true

security.oauth2.client.user-authorization-uri使用者跳轉去擷取access token的URI.

security.oauth2.resource.id指定resource的唯一辨別.

security.oauth2.resource.jwt.key-uriJWT token的URI. 當key為公鑰時,或者value不指定時指定.

security.oauth2.resource.jwt.key-valueJWT token驗證的value. 可以是對稱加密或者PEMencoded RSA公鑰. 可以使用URI作為value.

security.oauth2.resource.prefer-token-info是否使用token info,預設為true

security.oauth2.resource.service-id指定service ID,預設為resource.

security.oauth2.resource.token-info-uritoken解碼的URI.

security.oauth2.resource.token-type指定當使用userInfoUri時,發送的token類型.

security.oauth2.resource.user-info-uri指定user info的URI

security.oauth2.sso.filter-order如果沒有顯示提供WebSecurityConfigurerAdapter時指定的Filter order.

security.oauth2.sso.login-path跳轉到SSO的登入路徑預設為/login.

security.require-ssl是否對所有請求開啟SSL,預設為false.

security.sessions指定Session的建立政策(always, never, if_required, stateless).

security.user.name指定預設的使用者名,預設為user.

security.user.password預設的使用者密碼.

security.user.role預設使用者的授權角色.

(7)資料庫遷移工具相關配置

SpringBoot支援了兩種資料庫遷移工具,一個是flyway,一個是liquibase。其本身也支援sql script,在初始化資料源之後執行指定的腳本。

flyway

flyway.baseline-description對執行遷移時基準版本的描述.

flyway.baseline-on-migrate當遷移時發現目标schema非空,而且帶有沒有中繼資料的表時,是否自動執行基準遷移,預設false.

flyway.baseline-version開始執行基準遷移時對現有的schema的版本打标簽,預設值為1.

flyway.check-location檢查遷移腳本的位置是否存在,預設false.

flyway.clean-on-validation-error當發現校驗錯誤時是否自動調用clean,預設false.

flyway.enabled是否開啟flywary,預設true.

flyway.encoding設定遷移時的編碼,預設UTF-8.

flyway.ignore-failed-future-migration當讀取中繼資料表時是否忽略錯誤的遷移,預設false.

flyway.init-sqls當初始化好連接配接時要執行的SQL.

flyway.locations遷移腳本的位置,預設db/migration.

flyway.out-of-order是否允許無序的遷移,預設false.

flyway.password目标資料庫的密碼.

flyway.placeholder-prefix設定每個placeholder的字首,預設${.

flyway.placeholder-replacementplaceholders是否要被替換,預設true.

flyway.placeholder-suffix設定每個placeholder的字尾,預設}.

flyway.placeholders.[placeholder name]設定placeholder的value

flyway.schemas設定需要flywary遷移的schema,大小寫敏感,預設為連接配接預設的schema.

flyway.sql-migration-prefix遷移檔案的字首,預設為V.

flyway.sql-migration-separator遷移腳本的檔案名分隔符,預設__

flyway.sql-migration-suffix遷移腳本的字尾,預設為.sql

flyway.tableflyway使用的中繼資料表名,預設為schema_version

flyway.target遷移時使用的目标版本,預設為latest version

flyway.url遷移時使用的JDBC URL,如果沒有指定的話,将使用配置的主資料源

flyway.user遷移資料庫的使用者名

flyway.validate-on-migrate遷移時是否校驗,預設為true.

liquibase

liquibase.change-logChange log 配置檔案的路徑,預設值為classpath:/db/changelog/db.changelog-master.yaml

liquibase.check-change-log-location是否堅持change log的位置是否存在,預設為true.

liquibase.contexts逗号分隔的運作時context清單.

liquibase.default-schema預設的schema.

liquibase.drop-first是否首先drop schema,預設為false

liquibase.enabled是否開啟liquibase,預設為true.

liquibase.password目标資料庫密碼

liquibase.url要遷移的JDBC URL,如果沒有指定的話,将使用配置的主資料源.

liquibase.user目标資料使用者名

(8)其他常用配置屬性

aop

spring.aop.auto是否支援@EnableAspectJAutoProxy,預設為: true

spring.aop.proxy-target-classtrue為使用CGLIB代理,false為JDK代理,預設為false

application

spring.application.admin.enabled是否啟用admin特性,預設為: false

spring.application.admin.jmx-name指定admin MBean的名稱,預設為: org.springframework.boot:type=Admin,name=SpringApplication

autoconfig

spring.autoconfigure.exclude配置要排除的Auto-configuration classes.

batch

spring.batch.initializer.enabled是否在必要時建立batch表,預設為true

spring.batch.job.enabled是否在啟動時開啟batch job,預設為true

spring.batch.job.names指定啟動時要執行的job的名稱,逗号分隔,預設所有job都會被執行

spring.batch.schema指定要初始化的sql語句路徑,預設:classpath:org/springframework/batch/core/[email protected]@[email protected]@.sql)

spring.batch.table-prefix指定批量處理的表的字首.

jmx

spring.jmx.default-domain指定JMX domain name.

spring.jmx.enabled是否暴露jmx,預設為true

spring.jmx.server指定MBeanServer bean name. 預設為: mbeanServer)

mail

spring.mail.default-encoding指定預設MimeMessage的編碼,預設為: UTF-8

spring.mail.host指定SMTP server host.

spring.mail.jndi-name指定mail的jndi名稱

spring.mail.password指定SMTP server登陸密碼.

spring.mail.port指定SMTP server port.

spring.mail.properties指定JavaMail session屬性.

spring.mail.protocol指定SMTP server使用的協定,預設為: smtp

spring.mail.test-connection指定是否在啟動時測試郵件伺服器連接配接,預設為false

spring.mail.username指定SMTP server的使用者名.

sendgrid

spring.sendgrid.password指定SendGrid password.

spring.sendgrid.proxy.host指定SendGrid proxy host.

spring.sendgrid.proxy.port指定SendGrid proxy port.

spring.sendgrid.username指定SendGrid username.

social

spring.social.auto-connection-views是否開啟連接配接狀态的視圖,預設為false

spring.social.facebook.app-id指定應用id

spring.social.facebook.app-secret指定應用密碼

spring.social.linkedin.app-id指定應用id

spring.social.linkedin.app-secret指定應用密碼

spring.social.twitter.app-id指定應用ID.

spring.social.twitter.app-secret指定應用密碼

參考:

Spring boot全局配置檔案:

https://blog.csdn.net/chuxue1989/article/details/79943923

Spring boot配置中文解析:

https://blog.csdn.net/qq_24084925/article/details/53341641

傳智播客《Spring Boot實戰與原理分析》視訊課程

(https://pan.baidu.com/s/1o9M2bGI 密碼:jxg8)

轉載請注明出處:https://blog.csdn.net/acmman/article/details/81835911

繼續閱讀