SpringBoot中 application.yml /application.properties經常使用配置介紹

# Tomcat
server:
  tomcat:
    uri-encoding: UTF-8
    max-threads: 1000
    min-spare-threads: 30
  port: 10444
  servlet:
    context-path: /admin
#文件上傳文件夾
upload:
    base:
        dir: D:/piyan/upload
    basedir: E:/cms
    

spring:
  resources:
    static-locations: classpath:/META-INF/resources/,classpath:/resources/,classpath:/static/,classpath:/public/,file:${upload.base.dir}
  profiles:
    active: dev
  jackson:
    date-format: yyyy-MM-dd HH:mm:ss
    time-zone: GMT+8
  servlet:
    multipart:
      max-file-size: 4096MB
      max-request-size: 4096MB
      enabled: true
  freemarker:
    suffix: .html
    request-context-attribute: request
    cache: false
  devtools:
    restart:
      enabled: false
      #additional-paths: src/main/java
      exclude: WEB-INF/*


cmodes:
  redis:
    open: true  # 是否開啓redis緩存  true開啓   false關閉
  shiro:
    redis: true # true表示shiro session存到redis裏,須要開啓redis,纔會生效【分佈式場景】

#mybatis
mybatis-plus:
  mapper-locations: classpath*:mapper/**/*.xml
  #實體掃描,多個package用逗號或者分號分隔
  typeAliasesPackage: cn.cmodes.modules.*.entity
  global-config:
    #主鍵類型  0:"數據庫ID自增", 1:"用戶輸入ID",2:"全局惟一ID (數字類型惟一ID)", 3:"全局惟一ID UUID";
    id-type: 2
    #字段策略 0:"忽略判斷",1:"非 NULL 判斷"),2:"非空判斷"
    field-strategy: 2
    #駝峯下劃線轉換
    db-column-underline: true
    #刷新mapper 調試神器
    refresh-mapper: true
    #數據庫大寫下劃線轉換
    #capital-mode: true
    # Sequence序列接口實現類配置
    #key-generator: com.baomidou.mybatisplus.incrementer.OracleKeyGenerator
    #邏輯刪除配置
    logic-delete-value: -1
    logic-not-delete-value: 0
    #自定義填充策略接口實現
    #meta-object-handler: com.baomidou.springboot.xxx
    #自定義SQL注入器
    sql-injector: com.baomidou.mybatisplus.mapper.LogicSqlInjector
  configuration:
    map-underscore-to-camel-case: true
    cache-enabled: false
    call-setters-on-nulls: true


logging:
  level: debug
  level.cn.cmodes: debug
  path: logs/
  file: admin.log

 

項目中常見配置:
服務端口
服務名稱
容器: 類型 如tomcat、undertow 程池大小 請求日誌和目錄
鏈接池配置:
sql鏈接配置
info配置:
模板配置
資源配置html

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視圖的後綴.

 messagesjava

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視圖的後綴.

 resourceredis

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:/

 multipartspring

multipart.enabled
是否開啓文件上傳支持,默認爲true
multipart.file-size-threshold
設定文件寫入磁盤的閾值,單位爲MB或KB,默認爲0
multipart.location
指定文件上傳路徑.
multipart.max-file-size
指定文件大小最大值,默認1MB
multipart.max-request-size
指定每次請求的最大值,默認爲10MB

 freemarkersql

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
設定須要解析的視圖名稱.

 thymeleafjson

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
指定使用模板的視圖名,多個以逗號分隔.

 mustcacheapi

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.

 jerseytomcat

spring.jersey.filter.order
指定Jersey filter的order,默認爲: 0
spring.jersey.init
指定傳遞給Jersey的初始化參數.
spring.jersey.type
指定Jersey的集成類型,能夠是servlet或者filter.

 

 

 

注意點:

 

1,原有的key,例如spring.jpa.properties.hibernate.dialect,按「.」分割,都變成樹狀的配置

2,key後面的冒號,後面必定要跟一個空格

3,把原有的application.properties刪掉。而後必定要執行一下  maven -X clean install

相關文章
相關標籤/搜索