Springboot Multi-environment configuration

Source: Internet
Author: User

springboot Multi-environment (dev, test, prod) configuration2017-07-17 10:33 1290 People read comments (0) favorite reports Classification:Spring Boot (6)

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Directory (?) [+]

Propertiest Configuration Format
在Spring Boot中多环境配置文件名需要满足application-{profile}.properties的格式,其中{profile}对应你的环境标识,比如:

Application-dev.properties: Development environment
Application-test.properties: Test environment
Application-prod.properties: Production environment
As to which specific configuration file will be loaded, it needs to be set in the Application.properties file by the Spring.profiles.active property, whose value corresponds to the {profile} value.

such as: Spring.profiles.active=dev will load the contents of the Application-dev.properties configuration file

Below, a sample experiment is performed with different service ports configured in different environments.
Create different profiles for each environment application-dev.properties, application-test.properties, application-prod.properties
All three files are set with different server.port properties, such as: Dev environment set to 8001,test environment set to 8002,prod environment set to 8003
Set Spring.profiles.active=dev in Application.properties, which means that the dev environment is set by default

Test loading of different configurations
    执行java -jar xxx.jar,可以观察到服务端口被设置为8001,也就是默认的开发环境(dev)    执行java -jar xxx.jar --spring.profiles.active=test,可以观察到服务端口被设置为8002,也就是测试环境的配置(test)    执行java -jar xxx.jar --spring.profiles.active=prod,可以观察到服务端口被设置为8003,也就是生产环境的配置(prod)

According to the above experiment, we can summarize the multi-environment configuration ideas as follows:
Configure common content in application.properties and set Spring.profiles.active=dev to the default configuration of the development environment
Configure different environments in Application-{profile}.properties
Activating configuration of different environments by command-line mode

Springboot Multi-environment configuration

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.