string_boot profile multi-environment support

 

Overview

Profile is spring's support for different configuration functions for different environments, and the environment can be switched by activating specified parameters, etc.

Multiple profile files

When the main configuration file is written, the file name can be application-{profile}.yml, and the application.yml configuration file is used by default

method one

Multiple configuration files, the above file name suffix is ​​the logo

 

application.yml activate development settings  

server:
  port: 8081
spring:
  profiles:
    active: dev

application-dev.yml

server:
  port: 8082

Start the project can find the port is 8082

Way two

Specify '---' three in the form of a yml document block-

Directory Structure

application.yml

server:
  port: 8081
spring:
  profiles:
    active: dev # 激活dev
# 文档快分隔符
---
server:
  port: 8082
spring:
  profiles: dev # 声明环境表示
---
server:
  port: 8082
spring:
  profiles: prod

You can see the port that activates the development environment

Way Three

Use command mode to activate on the basis of mode one or mode two

 

Or type the project into a jar package and test it in the cmd command

 

--

Way Four

Virtual machine parameters

 

 

 

 

 

 

Guess you like

Origin blog.csdn.net/adminBfl/article/details/100606349