springboot multi-environment (dev, test, prod) configuration

Recap

In our development work, often because of configuration problems, dizziness and made big brain. Development environment, test environment configurations vary, database, redis, registry, etc. parameters are inconsistent, if placed in the same configuration file, you will find a lot of comments, published in different environments, we need to modify the configuration parameters of different environments . Multi-environment configuration spring boot on a good solution to this problem. The different parameters for different environments configured in a different configuration file, where you need to configure which profile is loaded on it. The following demonstrates this:

Configuration

  • Here are all of four profiles
  • application.properties Configuration
  • application-dev.properties Configuration (configure the development environment)
  • application-test.properties configuration (test environment configuration)
  • application-prod.properties configuration (production configuration)

  • application.properties Configuration

  • application-dev.properties Configuration

  • application-test.properties Configuration

  • application-prod.properties Configuration

  • Needs which profile is loaded, modified application.properties file spring.profiles.active = dev parameter can be

    test

  • Development environment configuration (modified in the application.properties spring.profiles.active = dev)
  • Test Environment Configuration (modified in the application.properties spring.profiles.active = test)

  • Production configuration (modified in the application.properties spring.profiles.active = prod)

to sum up

It can be seen for the above examples:

  • By modifying application.properties loading configuration file corresponding to the parameter determination spring.profiles.active environment
  • 以上整合dev:port=6677,test:port=6679,prod:port=6678,通过控制日志可以看出,正确加载了不同环境的配置参数

Guess you like

Origin www.cnblogs.com/qinshengfei/p/12157135.html