Spring boot uses profile to differentiate between formal environment profile and test environment configuration file

Source: Internet
Author: User

Reprint please indicate the author and source at the top of the page

A: Preface

Often at the time of development, the configuration files in the project, in the personal development of a set of configuration files, a set of configuration files in the test environment, a set of configuration files in the formal environment, this time if the configuration file complex, need to change a lot of things, and because of the iterative process, it is necessary to switch frequently, problems inevitably occur.

Two: the solution of Springboot

In fact, the preparation should be said to be the spring solution, because these spring boot is also based on the functionality of spring, of course, spring boot must be much simpler.

2.1: Prepare multiple configuration files

First prepare two files in the Src/main/resource, respectively, is a formal configuration file, a test configuration file, the name of the configuration file is as follows

Application-test.yml

Content:

Project:  Name: Formal environment

Application-pro.yml

Project:  Name: Test environment

Then there is a application.yml file, which is the primary file, and spring boot will load the file first

Then spring boot is configured as follows:

Spring:  Profiles:    Active:pro

As above, the Pro configuration file is enabled.

You can also enable multiple configuration files at the same time

Spring:  Profiles:    active:pro,test

The line is separated by commas.

Spring boot uses profile to differentiate between formal environment profile and test environment configuration file

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.