1. 程式人生 > >(轉)SpringBoot常用配置

(轉)SpringBoot常用配置

前言:springboot集成了主流的第三方框架,但是需要使用springboot那一套配置方式。但是我這裡只列舉了非常非常常用的,可以看已發的幾篇部落格,慢慢會補充。當然官方文件裡也有相應的配置,可惜沒有註釋。

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.