1) SpringBoot特點
- 特點:約定優于配置
2) YAML配置文件
-
語法特點:
- 大小寫敏感
- 使用空格縮進表示層級關系
- 縮進的空格數目沒有要求,同級元素左側對齊即可
- 使用 # 注釋,只有行注釋,沒有塊注釋
- key 與 value 用 : 加上空格來分割
-
基本組件
- 對象(映射/字典)
- 數組(列表)
# 對象
person:
name: LC
age: 25
# 數組
- a
- b
- 支持的數據類型
# 字符串
string: hello
# 布爾值
boolean: true
# 數值(整型、浮點)
number: 123
# Null
null: ~
# 日期時間(Date、Time)
date: 2019-06-09
- SpringBoot常用配置
spring:
# 數據源配置
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
# 配置獲取連接等待超時的時間
maxWait: 60000
# 配置間隔多久才進行一次檢測,檢測需要關閉的空閑連接,單位是毫秒
timeBetweenEvictionRunsMillis: 60000
# 配置一個連接在池中最小生存的時間,單位是毫秒
minEvictableIdleTimeMillis: 300000
# http請求
http:
#json序列化框架
converters:
preferred-json-mapper: fastjson
#上傳文件、請求最大限制
multipart:
max-file-size: 50MB
max-request-size: 50MB
# Spring MVC配置
mvc:
dispatch-options-request: true
static-path-pattern: /**
# 激活環境配置
profiles:
active: local
# Redis配置
redis:
host: 127.0.0.1
port: 6379
# 應用名
application:
name: springboot
# Redis客戶端
jedis:
pool:
host: 127.0.0.1
port: 6379
# 線程池的配置文件
threads:
pool:
queueCapacity: 50
corePoolSize: 20
maxPoolSize: 50
keepAliveSeconds: 600
# 日志級別
logging:
level: info
# Web服務器
server:
# 超時時間
session:
timeout: 60
# 端口
port: 8080
# 根路徑
context-path: /springboot