Spring Boot base 3-configuration file Details: properties and Yaml

Source: Internet
Author: User

Source Address: Https://github.com/roncoo/spring-boot-demo

I. The order in which the configuration files are effective, the values are overwritten:

1. @TestPropertySource annotations

2. Command-line arguments

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

4. Operating system Environment variables

5. Only the attributes contained in the random.* will produce a randomvaluepropertysource

6. Application configuration file (Application.properties, including YAML and profile variables) outside the packaged jar

7. Application configuration file (Application.properties, including YAML and profile variables) within the packaged jar

8. @propertysource annotations on the @configuration class

9. Default properties (specified with springapplication.setdefaultproperties)

Two Configure random values

Roncoo.secret=${random.value}

Roncoo.number=${random.int}

Roncoo.bignumber=${random.long}

Roncoo.number.less.than.ten=${random.int (10)}

RONCOO.NUMBER.IN.RANGE=${RANDOM.INT[1024,65536]}

Read using annotations: @Value (Value = "${roncoo.secret}")

Note: The yellow dot hint is to prompt for configuration metadata, you can not configure

Three Property placeholder

When values in Application.properties are used, they are filtered by the presence of environment, so you can refer to previously defined values (for example, System Properties).

Roncoo.name=www.roncoo.com

Roncoo.desc=${roncoo.name} is a domain name

Four Application properties file, sorted by priority, high position will cover low

1. A/config subdirectory under the current directory

2. Current directory

3. A/config bag under a classpath

4. Classpath root Path (root)

This list is sorted by priority (the high position in the list will have a low coverage position)

Five. Introduction to configuring Application ports and other configurations

#端口配置:

server.port=8090

#时间格式化

SPRING.JACKSON.DATE-FORMAT=YYYY-MM-DD HH:mm:ss

#时区设置

Spring.jackson.time-zone=asia/chongqing

Six. Use Yaml instead of properties

Note: Add a space after the colon

Project Source Address

Follow me:

Spring Boot base 3-configuration file Details: properties and Yaml

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.