多环境配置文件名需要使用application-{profile}.properties的格式。
使用spring.profiles.active激活哪个配置。
排序规则:先按照位置读取优先级,在同一位置ProFiles优先级最高,同一位置中如果没有ProFiles 则顺序为:yml--yaml--properties
案例
#application.yaml文件
server:
port: 8080
servlet:
context-path: /hello
spring:
profiles:
active: pro
#application-uat.yaml文件
server:
port: 8081
#application-pre.yaml文件
server:
port: 8082
#application-pro.yaml文件
server:
port: 8083
此时会读取pro的相关配置
java -jar 形式
命令行定位配置
命令行重新注入激活配置
使用spring.config.location 定位配置文件(不会进行互补)
使用spring.config.name指定配置文件(不会进行互补)