Spring Boot Spring Cloud distinguishes development environment test environment pre-release environment (gray environment) formal environment

 The difference between each environment

Development environment (dev): the environment used during development

Test environment (test): daily test or test before going online.

Pre-release environment (grayscale environment) (pre): The final debugging before release, the data source is consistent with the official environment.

Formal environment (prod): literally

configuration

Copy 4 application.yml of the project and directory:

application-dev.yml

application-test.yml

application-pre.yml

application-prod.yml

The main configuration file application.yml only needs a few simple configuration lines (server.port is used to set the port number, which is omitted here).

spring:
  application:
    name: test-service#微服务ID
  profiles:
    active: dev #对应环境

Other messy database links, log directories, etc. can be thrown into the configuration file of the corresponding environment.

Collocation configuration center (recommended)

It is recommended to use it with the configuration center to facilitate subsequent management.

If it is used with the configuration center, the configuration will be simpler. The main file application.yml still only needs the above few items. For the corresponding environment, you only need to add the registration center and the registration address configuration of the configuration center. The rest Configurations are dynamically configured directly in the configuration center.

#开发环境
spring:
  cloud:
    nacos:
      discovery:
        server-addr: 192.168.2.200:8848
      config:
        server-addr: 192.168.2.200:8848
        file-extension: yaml

run

When packaging, just pack it directly. You don’t need to modify the active field in application.yml. You only need to dynamically set the active field to the environment you need in the running command line.

java -jar test-service.jar --spring.profiles.active=test 

Guess you like

Origin blog.csdn.net/qq_33601179/article/details/122124628