Spring Boot configuration file-Multi-environment configuration

Source: Internet
Author: User

I. benefits of multi-environment configuration:

1. different environment configuration can be configured with different parameters ~

2. Easy to deploy, improve efficiency, reduce error ~

Two. Properties Multi-environment configuration

1. Configure activation options

Spring.profiles.active=dev

2. Add additional Profiles

Application.properties:

#激活哪一个环境的配置文件spring. profiles.active=dev# Public configuration Spring.jackson.date-format=yyyy-mm-dd HH:MM:SS:

You can also create an active environment when running

--spring.profiles.active=prd

three . YAML Multi-environment configuration

1. Configure activation options

Spring:     Profiles:        Active:dev    

2. Add three short lines in the configuration file to distinguish between the two English states

---Spring:   profiles:dev

Application.yml

#激活哪一个环境的配置文件Spring:  Profiles:    active:prd# public configuration Spring:  Jackson:    Date-format : Yyyy-mm-dd HH:mm:ss---Spring:  profiles:devserver:  port:8081---Spring:  profiles:testserver:  port:8082---Spring:  profiles:prdserver:  port:8083

This situation is an error: Duplicate key:spring

The correct configuration:

#激活哪一个环境的配置文件 # Public configuration spring:  profiles:    active:prd  Jackson:    date-format:yyyy-mm-dd hh:mm: SS---Spring:  profiles:devserver:  port:8081---Spring:  profiles:testserver:  port:8082---Spring:  profiles:prdserver:  port:8083

Four . Comparison of two configuration methods

1. Properties configuration Multi-environment, need to add multiple configuration files, Yaml only need one accessory file

The yml file itself has the ability to differentiate between different environments

2. The difference in writing format, Yaml relatively concise, elegant

3. Yaml's disadvantage: it cannot be loaded by @propertysource annotations. If you need to load values using @propertysource annotations, use the properties file.

True, or like the configuration form of properties, yml form of elegance? No feeling ~ haha ~

Spring Boot configuration file-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.