實際開發中,會有很多種環境的切換,本地,測試,生產等,各環境的信息都可能不同,這時候需要配置多環境的yml文件,如下:
1:配置一個主的application.yml文件
spring:
profiles:
# 環境分支:dev本地分支|test測試分支|prod生產分支
active: test
# 配置pagehelper參數
pagehelper:
helperDialect: mysql
reasonable: true
supportMethodsArguments: true
params: count=countSql
2:配置本地的yml:命名以:application-dev.yml
#用於配置開發壞境信息
#配置服務端口號
server:
port: 8080
servlet:
context-path: /path
session:
timeout: 1800s
# 配置數據庫信息
spring:
datasource:
url: jdbc:mysql://localhost:3306/***?useUnicode=true&characterEncoding=utf-8&serverTimezone=UTC
username: root
password: root
driver-class-name: com.mysql.jdbc.Driver
#Mybatis的mapper.xml文件位置
mybatis:
mapper-locations: classpath:mapper/*.xml
#配置日誌輸出位置
logging:
file:
path: D:\log
其他環境的yml文件類似上面,自己根據實際情況進行配置即可!!!