java SpringBoot switches between different operating environments (production environment, development environment, test environment) SpringBoot configures multiple different operating environments [multi-file version]

Background: The same set of Spring Boot applications will be installed in different environments, such as: development, testing, production, etc. Among them, the most modified ones are nothing more than the configuration of the database address, server port, etc.

Use the profile function to switch between different operating environments (production environment, development environment, and test environment)

yml file

yml configuration file naming method

application-dev.yml
application-pro.yml
application-test.yml

Here we must pay attention to the dash

yml file writing method

spring:
  #切换项目环节 active 的值 dev 当前运行环境配置文件后缀
  profiles:
    active: dev

java SpringBoot switches different operating environments (production environment, development environment, test environment) SpringBoot configures different operating environments

The above code corresponds to the application-dev.yml file
java SpringBoot switches different operating environments (production environment, development environment, test environment) SpringBoot configures different operating environments

properties file

properties configuration file naming method

application-dev.properties
application-pro.properties
application-test.properties

Here we must pay attention to the dash

Properties file writing method

spring.profiles.active=dev

java SpringBoot switches different operating environments (production environment, development environment, test environment) SpringBoot configures different operating environments
insert image description here

Guess you like

Origin blog.csdn.net/gjwgjw1111/article/details/131114014