springboot一鍵application.yml配置文件實踐
更新時間:2026年02月24日 08:35:03 作者:月華白晝
application-dev.yml文件是Spring Boot項目中用于定義開發(fā)環(huán)境配置的一個YAML格式文件,它包含了數據庫連接、服務器端口、日志級別、緩存配置等開發(fā)過程中常用的設置,通過這個文件,開發(fā)者可以在不同的環(huán)境中(如開發(fā)、測試、生產)切換配置,而無需修改代碼
springboot application.yml配置文件
server :
port : 8080
##項目名字配置
#servlet :
# context-path : /demo
tomcat :
uri-encoding : UTF-8
#xx 報錯修改的地方
max-connections: 200000
max-http-form-post-size: 9000000
threads:
max: 128
min-spare: 5
spring :
# 環(huán)境 dev|test|prod
profiles :
active : dev
#引入其他配置文件,例如ftpHX 未配置文件application-ftpHX.yml
#include: ftpHX,ftpCloud
servlet:
multipart:
#設置總上傳的數據大小
max-request-size: 100MB
#單個文件大小
maxFileSize : 30MB
#xx 報錯修改的地方
max-connections: 200000
max-http-post-size: 9000000
#熱部署模塊
devtools:
restart:
#熱部署開關
enabled: true
#指定熱部署的目錄
additional-paths: src/main/java
#指定目錄不更新
exclude: test/**
mvc: #靜態(tài)文件
static-path-pattern : /static/**
pathmatch:
matching-strategy: ant_path_matcher
#模板引擎
thymeleaf:
model: HTML5
prefix: classpath:/templates/
suffix: .html
#指定編碼
encoding: utf-8
#禁用緩存 默認false
cache: false
jackson:
time-zone: GMT+8
date-format: yyyy-MM-dd HH:mm:ss
redis:
ssl: false
database: 0
host: 127.0.0.1
port: 6379
password:
timeout: 1000
lettuce:
pool:
max-active: 200
max-wait: -1
max-idle: 10
min-idle: 0
#mybatis:
# #配置mapper的掃描,找到所有的mapper.xml映射文件
# mapperLocations : classpath*:mybatis/*/*.xml
# #mybatis提供三種sql執(zhí)行器,分別是SIMPLE、REUSE、BATCH。
# executor-type : reuse
# #搜索指定包別名
# typeAliasesPackage : com.*.model
# #該配置項就是指將帶有下劃線的表字段映射為駝峰格式的實體類屬性。
# configuration :
# map-underscore-to-camel-case : true
# 控制臺輸出sql、下劃線轉駝峰
mybatis-plus:
mapper-locations: classpath:/mybatis-plus/*.xml
typeAliasesPackage: com.fc.pilotSchool.model
# 控制臺輸出sql、下劃線轉駝峰
configuration:
log-impl: org.apache.ibatis.logging.stdout.StdOutImpl
map-underscore-to-camel-case: true
#pagehelper分頁插件
pagehelper:
helperDialect: mysql
reasonable: true
supportMethodsArguments: true
params: count=countSql
oss:
enable: true
info: true
path-style-access: false #使用云OSS 需要關閉
endpoint: http://127.0.0.1:9000 #對應上圖 ③ 處配置
access-key: minioadmin # 上文創(chuàng)建的AK
secret-key: minioadmin # 上文創(chuàng)建的SK
bucket-name: v2-cloud # 上文創(chuàng)建的桶名稱
application-dev.yml文件
#dev環(huán)境 mysql7.0
spring:
datasource:
type: com.alibaba.druid.pool.DruidDataSource
driverClassName: com.mysql.cj.jdbc.Driver
#druid連接池配置
druid:
#主庫數據源
master:
url: jdbc:mysql://xxx.xxx.xxx.xxx:3306/xxxx?useUnicode=true&characterEncoding=UTF-8&useSSL=false&autoReconnect=true&failOverReadOnly=false&serverTimezone=GMT
username: xxxxx
password: xxxxx
#備數據源 #關閉
slave:
enabled: false
url: jdbc:mysql://localhost:3306/xxxx?useUnicode=true&characterEncoding=UTF-8&serverTimezone=GMT&autoReconnect=true&useSSL=false
username: xxxx
password: xxxx
#配置初始化連接數大小
initial-size: 10
# 最大連接數
maxActive: 50
#最小連接數
minIdle: 10
#獲取連接等待超時時間
maxWait: 5000
poolPreparedStatements: true #是否緩存preparedStatement,也就是PSCache。PSCache對支持游標的數據庫性能提升巨大,比如說oracle。在mysql下建議關閉。
maxPoolPreparedStatementPerConnection-size: 20
validationQuery: SELECT 1 FROM DUAL
validationQueryTimeout: 20000
testOnBorrow: false #申請連接時執(zhí)行validationQuery檢測連接是否有效,做了這個配置會降低性能。
testOnReturn: false #歸還連接時執(zhí)行validationQuery檢測連接是否有效,做了這個配置會降低性能。
testWhileIdle: true #建議配置為true,不影響性能,并且保證安全性。申請連接的時候檢測,如果空閑時間大于timeBetweenEvictionRunsMillis,執(zhí)行validationQuery檢測連接是否有效。
timeBetweenEvictionRunsMillis: 60000 #配置間隔多久才進行一次檢測,檢測需要關閉的空閑連接,單位是毫秒
minEvictableIdleTimeMillis: 300000 #一個連接在池中最小生存的時間,單位是毫秒
maxEvictableIdleTimeMillis: 900000 # 配置一個連接在池中最大生存的時間,單位是毫秒
#StatViewServlet配置。(因為暴露的監(jiān)控信息比較敏感,支持密碼加密和訪問ip限定)
webStatFilter:
enabled: true
statViewServlet:
enabled: true
urlPattern: /druid/*
#可以增加訪問賬號密碼【去掉注釋就可以】
#login-username: admin
#login-password: admin
filter:
stat:
enabled: true
# 慢SQL記錄
log-slow-sql: true
slow-sql-millis: 1000
merge-sql: true
wall:
config:
multi-statement-allow: true
#mysql 8.0
#spring:
# datasource:
# type: com.alibaba.druid.pool.DruidDataSource
# driverClassName: com.mysql.cj.jdbc.Driver
# #druid連接池配置
# druid:
# # 主庫數據源
# master:
# url: jdbc:mysql://localhost:3306/test?useUnicode=true&characterEncoding=UTF-8&serverTimezone=GMT&autoReconnect=true&useSSL=false
# username: root
# password: root
# #樹熊數據源
# slave:
# enabled : false
# url: jdbc:mysql://localhost:3306/test2?useUnicode=true&characterEncoding=UTF-8&serverTimezone=GMT&autoReconnect=true&useSSL=false
# username: root
# password: root
# #配置初始化連接數大小
# initial-size: 10
# # 最大連接數
# max-active: 50
# #最小連接數
# min-idle: 10
# #獲取連接等待超時時間
# max-wait: 5000
# pool-prepared-statements: true #是否緩存preparedStatement,也就是PSCache。PSCache對支持游標的數據庫性能提升巨大,比如說oracle。在mysql下建議關閉。
# max-pool-prepared-statement-per-connection-size: 20
# validation-query: SELECT 1 FROM DUAL
# validation-query-timeout: 20000
# test-on-borrow: false #申請連接時執(zhí)行validationQuery檢測連接是否有效,做了這個配置會降低性能。
# test-on-return: false #歸還連接時執(zhí)行validationQuery檢測連接是否有效,做了這個配置會降低性能。
# test-while-idle: true #建議配置為true,不影響性能,并且保證安全性。申請連接的時候檢測,如果空閑時間大于timeBetweenEvictionRunsMillis,執(zhí)行validationQuery檢測連接是否有效。
# time-between-eviction-runs-millis: 60000 #配置間隔多久才進行一次檢測,檢測需要關閉的空閑連接,單位是毫秒
# min-evictable-idle-time-millis: 300000 #一個連接在池中最小生存的時間,單位是毫秒
# #StatViewServlet配置。(因為暴露的監(jiān)控信息比較敏感,支持密碼加密和訪問ip限定)
# stat-view-servlet:
# enabled: true
# url-pattern: /druid/*
# #可以增加訪問賬號密碼【去掉注釋就可以】
# #login-username: admin
# #login-password: admin
# filter:
# stat:
# log-slow-sql: true
# slow-sql-millis: 1000
# merge-sql: true
# wall:
# config:
# multi-statement-allow: true
總結
以上為個人經驗,希望能給大家一個參考,也希望大家多多支持腳本之家。
您可能感興趣的文章:
- SpringBoot application.yml配置文件使用及說明
- Springboot的application.properties或application.yml環(huán)境的指定運行與配置方式
- SpringBoot配置文件中常用配置屬性詳解(application.properties/application.yml)
- 解決SpringBoot啟動報錯:Failed?to?load?property?source?from?location?'classpath:/application.yml'問題
- 深度對比與解析SpringBoot中的application.properties與application.yml
- SpringBoot項目中application.yml和bootstrap.yml文件的區(qū)別及說明
相關文章
springboot 整合druid數據庫密碼加密功能的實現代碼
這篇文章主要介紹了springboot 整合druid數據庫密碼加密功能的實現代碼,本文給大家介紹的非常詳細,對大家的學習或工作具有一定的參考借鑒價值,需要的朋友可以參考下2021-01-01
springboot反爬蟲組件kk-anti-reptile的使用方法
這篇文章主要介紹了springboot反爬蟲組件kk-anti-reptile的使用方法,幫助大家更好的利用spring boot反爬蟲,保護網站安全,感興趣的朋友可以了解下2021-01-01

