前言
spring配置文件指定使用哪个配置
一、不同的spring配置文件
application.yml
application.properties
代码如下(示例):
# 指定激活哪个profile就是 application- 后的值spring.profiles.active = dev
#即代表使用的是 application-dev.yml 或者是 application-dev.properties
#1.配置文件的方式 spring.profiles.active=xxx
#2.命令行的方式 --spring.profiles.active=xxx
#3.虚拟机的方式 -Dspring.profiles.active=xxx
二、同一个配置文件
各个模块间使用 - - -分割
server:
port: 8081 #端口为8081
spring:
profiles:
active: dev
#使用application-dev.yml中的配置(或当前配置文件中的dev模块)
#如当前配置使用当前文件中的dev模块上面的8081就不会生效
---
server:
port: 8088
#指定此peofile为 dev
spring:
profiles: dev
# 可以在同一个配置文件中设置多个配置 使用spring.profiles来指定当前部分的名称再通过上面第3行配置来指定使用哪个
---
server:
port: 8088
#指定此peofile为 dev
spring:
profiles: deva
---
#查看springboot启动了哪些自动配置
debug: true