当前位置:网站首页>05 Detailed explanation of the global configuration file application.properties
05 Detailed explanation of the global configuration file application.properties
2022-07-30 04:32:00 【m0_54861649】
Spring Boot provides a lot of automatic configuration, which greatly simplifies the development process of spring applications. When a user creates a Spring Boot project, even without any configuration, the project can run smoothly.Of course, users can also use the configuration file to modify the default settings of Spring Boot according to their own needs.
SpringBoot uses the following two global configuration files by default, and their file names are fixed.
- application.properties
- application.yml
application.properties and application.yaml can both be used as Spring Boot configuration files, but the writing format is different, and they are automatically read when Spring Boot starts.Of course, it can also be used at the same time, but the order of reading in the same directory is to read application.properties first, and then read application.yaml.The storage path of the configuration file is shown in the following figure.

In this section we will introduce the syntax and usage of application.properties in detail
The following is a simple application.properties properties configuration file.
server.port=8080
properties syntax
The syntax of properties is as follows:
- Use the key=value form of properties
- Use a hierarchical progression relationship.
- From the highest level to the lowest level, one by one, use the dot "." interval in the middle
Example:
server.address=localhost/170.20.10.112 #Can write IP or domain nameserver.port=80 #Indicates listening port 80, the default is 8080spring.datasource.driver-class-name=com.mysql.jdbc.Driver #Database driverspring.datasource.url=jdbc:mysql://localhost:3306/cqyddx?useUnicode=true&characterEncoding=UTF-8&allowPublicKeyRetrieval=true&useSSL=false&serverTimezone=Asia/Shanghaispring.datasource.username=rootspring.datasource.password=root
Common usage of properties
properties supports the following three data structures:
- Object: A collection of key-value pairs
- Array: A set of values in order
- Literal: a single, indivisible value
properties literals
A literal is a single, unsplittable value such as a number, string, boolean, and date.
In properties, use the form of "key[=]value**"** to represent a pair of key-value pairs (spaces cannot be omitted), such as name="xiatian", age=32.
The literal can be written directly in the "value" of the key-value pair, and by default, the string does not need to use single or double quotation marks.
name="xiatian"age=32
If the string uses single quotes, special characters are escaped.
name="zhangsan ' **'**lisi"The output is: zhangsan lisi
If the string uses single quotes, special characters are escaped.
name="zhangsan lisi"The output is:
- zhangsan
- lisi
properties object writing
In properties, an object may contain multiple properties, each of which is a key-value pair.
properties provides the following notation for objects:
Use progression to represent the hierarchical relationship between objects and properties.
user.name="xiatian"user.age=32
properties array writing
properties use [x] to represent the elements in the array, the common writing is as follows:
user.books[0]=“biancheng0”user.books[1]="biancheng1"
user.books[2]="biancheng2"
user.books[3]="biancheng3"
Composite structure
The above three data structures can be used in any combination to achieve different user requirements, such as:
user.name="xiatian"
user.age=32
user.books[0]=“biancheng0”
user.books[1]="biancheng1"
user.books[2]="biancheng2"
user.books[3]="biancheng3"
user.cat.name=“diudiu”
Let me introduce myself first. The editor graduated from Shanghai Jiaotong University in 2013. I worked in a small company and went to big factories such as Huawei and OPPO. I joined Alibaba in 2018, until now.
I know that for most junior and intermediate java engineers, if they want to show their skills, they often need to explore their own growth or sign up to study, but for training institutions, the tuition fee is nearly 10,000 yuan.Self-learning that is not systematic is very inefficient and lengthy, and it is easy to hit the ceiling and the technology stops.
Therefore, I have collected a copy of "a complete set of learning materials for java development" for everyone. The original intention is also very simple. It is to help friends who want to learn by themselves but don't know where to start, and at the same time reduce everyone's burden.
Click the business card below to receive a full set of learning materials for java development
边栏推荐
- 权值线段树+线段树分裂/合并+CF1659D
- SQL Server data type conversion function cast () and convert () explanation
- 【Untitled】
- 【线性表】- LeetCode力扣三道练习题详解
- [SQL] at a certain correlation with a table of data update another table
- SQLSERVER merges subquery data into one field
- 【软件工程之美 - 专栏笔记】31 | 软件测试要为产品质量负责吗?
- C. Qualification Rounds(思维,特情)
- SSM框架简单介绍
- Drools (7): WorkBench
猜你喜欢

PyG builds R-GCN to realize node classification

unity初学5 摄像机跟随,边界控制以及简单的粒子控制(2d)

Unity beginner 5 cameras follow, border control and simple particle control (2 d)

精品MySQL面试题,备战八月99%必问!过不了面试算我的

使用EFR32作为Zigbee/Thread的sniffer的用法

New LaaS protocol Elephant Swap provides ePLATO with sustainable premium space

How to extract year, month and day data in date type in SQL Server

My first experience of Go+ language——Blessing message system, so that she can also feel your blessings
![[The Mystery of Cloud Native] Cloud Native Background && Definition && Detailed explanation of related technologies?](/img/eb/0cd6891fcc00d2c01ba8bd7f8d0822.png)
[The Mystery of Cloud Native] Cloud Native Background && Definition && Detailed explanation of related technologies?

代码开源设计实现思路
随机推荐
The first immersive and high-fidelity metaverse in China, Xiyuan Universe is officially launched
MySQL 安装报错的解决方法
The leap second that may cause the next "Millennium Bug" is boycotted by tech giants
Drools (7): WorkBench
2.6基数排序(桶排序)
恐造成下一个“千年虫”的闰秒,遭科技巨头们联合抵制
New LaaS protocol Elephant Swap provides ePLATO with sustainable premium space
SQLSERVER merges subquery data into one field
unity初学5 摄像机跟随,边界控制以及简单的粒子控制(2d)
【Redis高手修炼之路】Jedis——Jedis的基本使用
【周周有奖】云原生编程挑战赛“边缘容器”赛道邀你来战!
成为一个合格的网安,你知道这些吗?
【 notes 】 the beauty of the software engineering - column 31 | software testing are responsible for the quality of products?
【MySQL系列】-B+树索引和HASH索引有什么区别
Go书籍大全-从初级到高级以及Web开发
【Untitled】
小程序 wx.miniProgram.navigateTo 跳转地址不能是tabbar地址
sql语句-如何以一个表中的数据为条件据查询另一个表中的数据
Reverse Theory Knowledge 3 [UI Modification]
C. Travelling Salesman and Special Numbers (二进制 + 组合数)