springboot一鍵application.yml配置文件實(shí)踐
更新時(shí)間:2026年02月24日 08:35:03 作者:月華白晝
application-dev.yml文件是Spring Boot項(xiàng)目中用于定義開發(fā)環(huán)境配置的一個(gè)YAML格式文件,它包含了數(shù)據(jù)庫連接、服務(wù)器端口、日志級(jí)別、緩存配置等開發(fā)過程中常用的設(shè)置,通過這個(gè)文件,開發(fā)者可以在不同的環(huán)境中(如開發(fā)、測試、生產(chǎn))切換配置,而無需修改代碼
springboot application.yml配置文件
server :
port : 8080
##項(xiàng)目名字配置
#servlet :
# context-path : /demo
tomcat :
uri-encoding : UTF-8
#xx 報(bào)錯(cuò)修改的地方
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:
#設(shè)置總上傳的數(shù)據(jù)大小
max-request-size: 100MB
#單個(gè)文件大小
maxFileSize : 30MB
#xx 報(bào)錯(cuò)修改的地方
max-connections: 200000
max-http-post-size: 9000000
#熱部署模塊
devtools:
restart:
#熱部署開關(guān)
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
#禁用緩存 默認(rèn)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
# #該配置項(xiàng)就是指將帶有下劃線的表字段映射為駝峰格式的實(shí)體類屬性。
# configuration :
# map-underscore-to-camel-case : true
# 控制臺(tái)輸出sql、下劃線轉(zhuǎn)駝峰
mybatis-plus:
mapper-locations: classpath:/mybatis-plus/*.xml
typeAliasesPackage: com.fc.pilotSchool.model
# 控制臺(tái)輸出sql、下劃線轉(zhuǎn)駝峰
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 需要關(guān)閉
endpoint: http://127.0.0.1:9000 #對(duì)應(yīng)上圖 ③ 處配置
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:
#主庫數(shù)據(jù)源
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
#備數(shù)據(jù)源 #關(guān)閉
slave:
enabled: false
url: jdbc:mysql://localhost:3306/xxxx?useUnicode=true&characterEncoding=UTF-8&serverTimezone=GMT&autoReconnect=true&useSSL=false
username: xxxx
password: xxxx
#配置初始化連接數(shù)大小
initial-size: 10
# 最大連接數(shù)
maxActive: 50
#最小連接數(shù)
minIdle: 10
#獲取連接等待超時(shí)時(shí)間
maxWait: 5000
poolPreparedStatements: true #是否緩存preparedStatement,也就是PSCache。PSCache對(duì)支持游標(biāo)的數(shù)據(jù)庫性能提升巨大,比如說oracle。在mysql下建議關(guān)閉。
maxPoolPreparedStatementPerConnection-size: 20
validationQuery: SELECT 1 FROM DUAL
validationQueryTimeout: 20000
testOnBorrow: false #申請(qǐng)連接時(shí)執(zhí)行validationQuery檢測連接是否有效,做了這個(gè)配置會(huì)降低性能。
testOnReturn: false #歸還連接時(shí)執(zhí)行validationQuery檢測連接是否有效,做了這個(gè)配置會(huì)降低性能。
testWhileIdle: true #建議配置為true,不影響性能,并且保證安全性。申請(qǐng)連接的時(shí)候檢測,如果空閑時(shí)間大于timeBetweenEvictionRunsMillis,執(zhí)行validationQuery檢測連接是否有效。
timeBetweenEvictionRunsMillis: 60000 #配置間隔多久才進(jìn)行一次檢測,檢測需要關(guān)閉的空閑連接,單位是毫秒
minEvictableIdleTimeMillis: 300000 #一個(gè)連接在池中最小生存的時(shí)間,單位是毫秒
maxEvictableIdleTimeMillis: 900000 # 配置一個(gè)連接在池中最大生存的時(shí)間,單位是毫秒
#StatViewServlet配置。(因?yàn)楸┞兜谋O(jiān)控信息比較敏感,支持密碼加密和訪問ip限定)
webStatFilter:
enabled: true
statViewServlet:
enabled: true
urlPattern: /druid/*
#可以增加訪問賬號(hào)密碼【去掉注釋就可以】
#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:
# # 主庫數(shù)據(jù)源
# master:
# url: jdbc:mysql://localhost:3306/test?useUnicode=true&characterEncoding=UTF-8&serverTimezone=GMT&autoReconnect=true&useSSL=false
# username: root
# password: root
# #樹熊數(shù)據(jù)源
# slave:
# enabled : false
# url: jdbc:mysql://localhost:3306/test2?useUnicode=true&characterEncoding=UTF-8&serverTimezone=GMT&autoReconnect=true&useSSL=false
# username: root
# password: root
# #配置初始化連接數(shù)大小
# initial-size: 10
# # 最大連接數(shù)
# max-active: 50
# #最小連接數(shù)
# min-idle: 10
# #獲取連接等待超時(shí)時(shí)間
# max-wait: 5000
# pool-prepared-statements: true #是否緩存preparedStatement,也就是PSCache。PSCache對(duì)支持游標(biāo)的數(shù)據(jù)庫性能提升巨大,比如說oracle。在mysql下建議關(guān)閉。
# max-pool-prepared-statement-per-connection-size: 20
# validation-query: SELECT 1 FROM DUAL
# validation-query-timeout: 20000
# test-on-borrow: false #申請(qǐng)連接時(shí)執(zhí)行validationQuery檢測連接是否有效,做了這個(gè)配置會(huì)降低性能。
# test-on-return: false #歸還連接時(shí)執(zhí)行validationQuery檢測連接是否有效,做了這個(gè)配置會(huì)降低性能。
# test-while-idle: true #建議配置為true,不影響性能,并且保證安全性。申請(qǐng)連接的時(shí)候檢測,如果空閑時(shí)間大于timeBetweenEvictionRunsMillis,執(zhí)行validationQuery檢測連接是否有效。
# time-between-eviction-runs-millis: 60000 #配置間隔多久才進(jìn)行一次檢測,檢測需要關(guān)閉的空閑連接,單位是毫秒
# min-evictable-idle-time-millis: 300000 #一個(gè)連接在池中最小生存的時(shí)間,單位是毫秒
# #StatViewServlet配置。(因?yàn)楸┞兜谋O(jiān)控信息比較敏感,支持密碼加密和訪問ip限定)
# stat-view-servlet:
# enabled: true
# url-pattern: /druid/*
# #可以增加訪問賬號(hào)密碼【去掉注釋就可以】
# #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
總結(jié)
以上為個(gè)人經(jīng)驗(yàn),希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。
您可能感興趣的文章:
- SpringBoot application.yml配置文件使用及說明
- Springboot的application.properties或application.yml環(huán)境的指定運(yùn)行與配置方式
- SpringBoot配置文件中常用配置屬性詳解(application.properties/application.yml)
- 解決SpringBoot啟動(dòng)報(bào)錯(cuò):Failed?to?load?property?source?from?location?'classpath:/application.yml'問題
- 深度對(duì)比與解析SpringBoot中的application.properties與application.yml
- SpringBoot項(xiàng)目中application.yml和bootstrap.yml文件的區(qū)別及說明
相關(guān)文章
Request對(duì)象如何獲取請(qǐng)求頭數(shù)據(jù)
這篇文章主要介紹了Request對(duì)象如何獲取請(qǐng)求頭數(shù)據(jù)問題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2024-07-07
springboot如何根據(jù)不同的日志級(jí)別顯示不同的顏色
這篇文章主要介紹了springboot如何根據(jù)不同的日志級(jí)別顯示不同的顏色問題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2023-08-08
springboot 整合druid數(shù)據(jù)庫密碼加密功能的實(shí)現(xiàn)代碼
這篇文章主要介紹了springboot 整合druid數(shù)據(jù)庫密碼加密功能的實(shí)現(xiàn)代碼,本文給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2021-01-01
Spring?Boot整合持久層之JPA多數(shù)據(jù)源
JPA(Java Persistence API)Java 持久化 API,是 Java 持久化的標(biāo)準(zhǔn)規(guī)范,Hibernate 是持久化規(guī)范的技術(shù)實(shí)現(xiàn),而 Spring Data JPA 是在 Hibernate 基礎(chǔ)上封裝的一款框架2022-08-08
java?io文件操作從文件讀取數(shù)據(jù)的六種方法
這篇文章主要為大家介紹了java?io操作總結(jié)從文件讀取數(shù)據(jù)的六種方法,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步早日升職加薪2022-03-03
springboot反爬蟲組件kk-anti-reptile的使用方法
這篇文章主要介紹了springboot反爬蟲組件kk-anti-reptile的使用方法,幫助大家更好的利用spring boot反爬蟲,保護(hù)網(wǎng)站安全,感興趣的朋友可以了解下2021-01-01

