SpringBoot 配置文件

1. 全局配置文件

  • application.properties
  • application.yml
  • 配置文件名是固定的;
  • 配置文件存放在src/main/resources目录或者类路径/config下;

2. Profile

  • Profile是Spring对不同环境提供不同配置功能的支持,可以通过激活,指定参数等方式快速切换环境;

2.1 多Profile文件

  • 主配置文件的文件名,可以是application-{profile}.properties;
  • 默认使用application.properties的配置;
  • 在配置文件中,使用application.profiles.active=dev激活使用;

2.2 yml支持的多文档块方式

server:
  port: 8081
spring:
  profiles:
    active: prod  # 激活生产环境

---
# 测试环境
server:
  port: 8083
spring:
  profiles: dev

---
# 生产环境
server:
  port: 8084
spring:
  profiles: prod

参考资料:

猜你喜欢

转载自www.cnblogs.com/linkworld/p/9135650.html