Java Spring Boot yml multi-environment split file management optimization

In the java Spring Boot yml multi-environment configuration above , we talked about multi-environment development, but putting these things together is still very easy to expose information
, and it is not very friendly to maintenance.

Here we create three files under resources called application-pro.yml application-dev.yml application-test.yml,
we directly convert the three environments into three configuration files
insert image description here
and then application-pro.yml The reference code is as follows

server:
  port: 80

The application-dev.yml reference code is as follows

server:
  port: 81

The final application-test.yml reference code is as follows

server:
  port: 82

OK, it's that simple. Three environments are directly configured with three files
, and then our application.yml is directly written like this

spring:
  profiles:
      active: pro

This is OK. Directly tell the startup project to use the pro environment through this grammar

Then we start the project, and
insert image description here
we can see that the port to start is on port 80,
which corresponds to our application-pro.yml file configuration
insert image description here
, and then we change application.yml to

spring:
  profiles:
      active: dev

Point to application-dev.yml to start the project
insert image description here
At this point, it points to application-dev.yml
and becomes 81.
We won’t try anything else

Guess you like

Origin blog.csdn.net/weixin_45966674/article/details/132274913