4. Profile of Spring Boot configuration file

Source: Internet
Author: User

Profile

1. Multiple profile files

When we write the main configuration file, the file name can be application-{profile}.properties/yml

Default use of application.properties configuration;

2, YML support multi-document block mode

Use --- to distinguish document one, document two, document three

Server:port:8081spring:profiles:active:prod‐‐‐server:port:8083spring:profiles:dev‐‐‐server:port:8084spring: Profiles:prod #指定属于哪个环境

3. Activate the specified profile

1. Specify spring.profiles.active=dev in the configuration file

2, command line: Java-jar Spring-boot-02-config-0.0.1-snapshot.jar (Project package file) --spring.profiles.active=dev; You can configure incoming command-line parameters directly at test time

3, virtual machine parameters; -dspring.profiles.active=dev

In the edit under the

Specify the file run location

6. configuration file Loading location

Springboot boot scans the application.properties or application.yml file at the following location as the default profile for spring boot

–file:./config/

–file:./

–classpath:/config/

–classpath:/

Priority is high and high priority configuration overrides low-priority configuration;

Springboot will load the master configuration file from all four locations, and the complementary configuration ;

We can also change the default configuration file location via Spring.config.location

After the project is packaged, we can use command-line arguments to specify a new location for the configuration file when the project is launched, and the configuration files that are loaded by default are used together to form a complementary configuration;

Java-jar Spring-boot-02-config-02-0.0.1-snapshot.jar--spring.config.location=g:/application.properties

7. External Configuration loading order

Springboot can also load configurations from the following locations, priority from high to low, high-priority configuration overrides low-priority configurations, and all configurations will form complementary configurations

1. Command-line arguments

All configurations can be specified on the command line

Java-jar spring-boot-02-config-02-0.0.1-snapshot.jar --server.port=8087--server.context-path=/abc

Multiple configurations separated by spaces;--Config item = value

2. Jndi Properties from Java:comp/env

3.Java System Properties (System.getproperties ())

4. Operating system Environment variables

random.* property value for 5.RandomValuePropertySource configuration

In the jar package outward jar package to look for, priority loading with profile

Application-{profile}.properties or Application.yml (with Spring.profile) profile outside the 6.jar package

Application-{profile}.properties or Application.yml (with Spring.profile) profile inside the 7.jar package

then load without profile.

Application.properties or Application.yml (without spring.profile) configuration file outside of the 8.jar package

9.jar application.properties or application.yml (without spring.profile) profile inside the package

[Email protected] @propertysource on the annotation class

11. Default properties specified by Springapplication.setdefaultproperties

All supported configurations are loaded from the source;

https://docs.spring.io/spring-boot/docs/1.5.9.RELEASE/reference/htmlsingle/#boot-features-external-config

4. Profile of Spring Boot 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.