09.YAML配置文件

1) SpringBoot特點(diǎn)

  1. 特點(diǎn):約定優(yōu)于配置

2) YAML配置文件

  1. 語法特點(diǎn):

    • 大小寫敏感
    • 使用空格縮進(jìn)表示層級(jí)關(guān)系
    • 縮進(jìn)的空格數(shù)目沒有要求,同級(jí)元素左側(cè)對(duì)齊即可
    • 使用 # 注釋,只有行注釋,沒有塊注釋
    • key 與 value 用 : 加上空格來分割
  2. 基本組件

    • 對(duì)象(映射/字典)
    • 數(shù)組(列表)
# 對(duì)象
person: 
    name: LC
    age: 25
    
# 數(shù)組
- a
- b

  1. 支持的數(shù)據(jù)類型
# 字符串
string: hello

# 布爾值
boolean: true

# 數(shù)值(整型、浮點(diǎn))
number: 123

# Null
null: ~

# 日期時(shí)間(Date、Time)
date: 2019-06-09
  • SpringBoot常用配置
spring:
  # 數(shù)據(jù)源配置
  datasource:
    type: com.alibaba.druid.pool.DruidDataSource
    url: jdbc:mysql://127.0.0.1:3306/spring_boot
    username: root
    password: 123456
    driver-class-name: com.mysql.jdbc.Driver
    name: druid
  druid:
    # 初始化大小,最小,最大
    initialSize: 5
    minIdle: 5
    maxActive: 20
    # 配置獲取連接等待超時(shí)的時(shí)間
    maxWait: 60000
    # 配置間隔多久才進(jìn)行一次檢測(cè),檢測(cè)需要關(guān)閉的空閑連接,單位是毫秒
    timeBetweenEvictionRunsMillis: 60000
    # 配置一個(gè)連接在池中最小生存的時(shí)間,單位是毫秒
    minEvictableIdleTimeMillis: 300000
  
  # http請(qǐng)求
  http:
    #json序列化框架
    converters:
      preferred-json-mapper: fastjson
    #上傳文件、請(qǐng)求最大限制
    multipart:
      max-file-size: 50MB
      max-request-size: 50MB

  # Spring MVC配置
  mvc:
    dispatch-options-request: true
    static-path-pattern: /**

  # 激活環(huán)境配置
  profiles:
    active: local

  # Redis配置
  redis:
    host: 127.0.0.1
    port: 6379

  # 應(yīng)用名
  application:
    name: springboot

# Redis客戶端
jedis:
  pool:
    host: 127.0.0.1
    port: 6379

# 線程池的配置文件
threads:
  pool:
    queueCapacity: 50
    corePoolSize: 20
    maxPoolSize: 50
    keepAliveSeconds: 600

# 日志級(jí)別
logging:
  level: info

# Web服務(wù)器
server:
  # 超時(shí)時(shí)間
  session:
    timeout: 60
  # 端口
  port: 8080
  # 根路徑
  context-path: /springboot
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

友情鏈接更多精彩內(nèi)容