springboot外部配置文件的引用,灵活切换多套配置文件

博客介绍了Spring Boot外部配置文件引用和多套配置文件切换的方法。通过spring.profiles.active和spring.profiles.include指定活动配置文件,还列举了resource目录下的多种配置文件,如application.properties等,并说明了部分配置文件的作用。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

外部配置文件引用

spring.profiles.active用来指定除了当前文件外,其他活动的配置文件。
例如spring.profiles.active=custom
其中custom指application.properties目录下的application-custom.properties
spring.profiles.include用来指定除了当前文件外,还有哪些活动的配置文件。
例如:通过spring.profiles.include=port,mysql

多套配置文件切换

resource目录下的配置文件包括:

  • application.properties
  • application-custom1.properties
  • application-custom2.properties
  • application-mysql.properties
  • application-port.properties
  • application-test-mysql.properties
  • application-test-port.properties

application.properties:

#spring.profiles.active=custom1通过切换custom1和2来切换正式和test环境
spring.profiles.active=custom2

application-custom1.properties:
配置该套配置中包含的文件

spring.profiles.include=test-port,test-mysql

application-custom2.properties:
配置该套配置中包含的文件

spring.profiles.include=port,mysql
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值