Springboot (2): Properties and Yaml configuration files

Source: Internet
Author: User

The order in which the configuration files are in effect overrides the values

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)

Second, configure the random value

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

Third, configuration 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


Example:

650) this.width=650; "src=" Https://s3.51cto.com/wyfs02/M01/98/6E/wKiom1k77HSQ7RnfAABTCOI4q9c666.jpg "title=" 1497099288 (1). jpg "alt=" wkiom1k77hsq7rnfaabtcoi4q9c666.jpg "/>

Application.properties configuration file:

################################# #服务器配置 ################################# #server. Port = 80server.tomcat.uri-enconding = utf-8################################# #随机数配置 ################################### 32-bit random number Roncoo.secret=${random.value} #数字随机数roncoo. number=${random.int}roncoo.number2.less.than.ten=${random.int (10)} roncoo.number3.in.range=${random.int[1024,65536]}################################# #配属性占位符配置 ################### ############## #roncoo. Name=zhangsanroncoo.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)


example, based on the above example, a copy of the application.properties configuration file is placed under the/config package under Classpath, as follows:

650) this.width=650; "src=" Https://s5.51cto.com/wyfs02/M00/98/6F/wKioL1k77UnDVOPkAADXqOYhSOM592.jpg "title=" 1497099540 (1). jpg "alt=" wkiol1k77undvopkaadxqoyhsom592.jpg "/>

650) this.width=650; "src=" Https://s2.51cto.com/wyfs02/M00/98/6F/wKiom1k77aLQlGdgAAAl2Qe94jY150.jpg "title=" 1497099632 (1). jpg "alt=" wkiom1k77alqlgdgaaal2qe94jy150.jpg "/>

Five. Introduction to configuring Application ports and other configurations

#端口配置:

server.port=8090

#时间格式化

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

#时区设置 (Chongqing, Asia)

Spring.jackson.time-zone=asia/chongqing


Note: The default time zone is not China, which is configured in Chongqing, Asia


If you set the time zone:

650) this.width=650; "src=" Https://s2.51cto.com/wyfs02/M01/98/6F/wKioL1k778nArpARAACtHSjHt9E346.jpg "title=" 1497100182 (1). jpg "alt=" wkiol1k778narparaacthsjht9e346.jpg "/>

Set the time zone for Chongqing, Asia:

650) this.width=650; "src=" Https://s1.51cto.com/wyfs02/M00/98/6F/wKioL1k78CqhhiixAADA0g9mtBc409.jpg "title=" 1497100271 (1). jpg "alt=" wkiol1k78cqhhiixaada0g9mtbc409.jpg "/>



Six. Use Yaml instead of properties

Note: Add a space after the colon

This article is from "I Love Big gold" blog, please be sure to keep this source http://1754966750.blog.51cto.com/7455444/1934134

Springboot (2): Properties and Yaml configuration files

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.