SpringBoot项目多环境开发

1.yml文件(旧)

说明:旧的写法。

#应用环境
spring:
  profiles:
    active: dev
---
#设置环境


#生产环境
spring:
  profiles: pro
server:
  port: 81

---
#开发环境
spirng:
  profiles: dev
server:
  port: 81


---
#测试环境
spring:
  profiles: test
server:
  port: 82

2.yml文件(新)

说明:以下是最新配置。

#应用环境
spring:
  profiles:
    active: test
---
#设置环境


#生产环境
spring:
  config:
    activate:
      on-profile: pro
server:
  port: 81

---
#开发环境
spring:
  config:
    activate:
      on-profile: dev
server:
  port: 81


---
#测试环境
spring:
  config:
    activate:
      on-profile: test
server:
  port: 82

3.文件区别

说明:可以创建不同的文件进行区分开发环境、测试环境、生产环境。在application.yml主文件配置。

SpringBoot项目多环境开发_第1张图片

spring:
  profiles:
    active: test

4.properties文件说明

SpringBoot项目多环境开发_第2张图片

5. 技巧

SpringBoot项目多环境开发_第3张图片

 

你可能感兴趣的:(spring,boot,数据库,后端)