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