Spring Boot Learning record 03_ some property profiles

Source: Internet
Author: User
Tags server port

Turn from: http://blog.didispace.com/springbootproperties/

Multi-environment configuration (this place is a bit like Maven's profile configuration)

When we develop spring boot applications, the same set of programs is usually applied and installed into several different environments, such as: development, testing, production, etc. Each environment's database address, server port and so on configuration will be different, if you are packaging for different environments to frequently modify the configuration file, it will be a very cumbersome and prone to error.

For a multi-environment configuration, the basic idea of a variety of project building tools or frameworks is consistent, and the Spring boot is no exception, or simpler, by configuring multiple profiles of different environments and then packaging them to specify what needs to be packaged.

In spring boot {profile} , the Multi-environment profile file application-{profile}.properties name needs to be in a format that corresponds to your environment identity, such as:

    • 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 application.properties to be set spring.profiles.active in the file by property, and {profile} its value corresponds to the value.

such as spring.profiles.active=test : The configuration application-test.properties file contents will be loaded

Below, a sample experiment is performed with different service ports configured in different environments.

    • Create a different profile application-dev.properties application-test.properties for each environment,application-prod.properties
    • All three files are set with server.port different properties, such as: Dev environment set to 1111,test environment set to 2222,prod environment set to 3333
    • Application.properties, which means that the dev environment is set by default spring.profiles.active=dev

According to the above experiment, we can summarize the multi-environment configuration ideas as follows:

    • application.propertiesThe common content is configured in and spring.profiles.active=dev set to the development environment as the default configuration
    • application-{profile}.propertiesConfigure different contexts in each environment
    • By default, the lower port is 8080.
    • Set server.port=8090 in application.properties
    • Add application-dev.properties, and set server.port=8070; application.properties settings Spring.profiles.active=dev

Spring Boot Learning record 03_ some property profiles

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.