【Spring Boot】(6)、Profile

Profile is Spring's support for providing different configuration functions for different environments, which can quickly switch environments by activating and specifying parameters.

1. Multiple Profile files (Properties format)

When the main configuration file is written, the file name can be application-{profile}.properties

  • application.properties: Default global configuration file

  • application-dev.properties: development environment

  • application-prod.properties: Production environment

  • application-test.properties: test environment


2, yml supports multi-document block mode

server:
  port: 8080
spring:
  profiles:
    active: dev

---
server:
  port: 8084
spring:
  profiles: dev


---
server:
  port: 8085
spring:
  profiles: prod


---
server:
  port: 8086
spring:
  profiles: test


3. Activate the specified Profile

  • Specify in the global configuration file to specify the current environment, and use the corresponding application-{profile}.properties or the configuration under the corresponding profile of application.yml as the configuration information used in the current environment.spring.profiles.active=...

  • Virtual machine parameters: ---> ---->Edit ConfigurationsVM options-Dspring.profiles.active=...

  • Command Line:

    • packaging commandjava -jar xxxx.jar --spring.profiles.active=...

    • IDEA run settings: ---> ---->Edit ConfigurationsProgram arguments--spring.profiles.active=xx



=====================Make an advertisement, welcome to pay attention =====================

QQ:
412425870
WeChat public account: Cay Classroom

csdn blog:
http://blog.csdn.net/caychen
Code cloud:
https://gitee.com/caychen/
github:
https://github.com/caychen

Click on the group number or scan the QR code to join the QQ group:

328243383 (1 group)




Click on the group number or scan the QR code to join the QQ group:

180479701 (2 groups)




Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325709289&siteId=291194637