当前位置:网站首页>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
边栏推荐
猜你喜欢

New LaaS protocol Elephant Swap provides ePLATO with sustainable premium space

GCC Rust获批将被纳入主线代码库,或将于GCC 13中与大家见面
Go 学习笔记(84)— Go 项目目录结构

Charles 替换 接口响应信息

MySQL installation error solution

cnpm安装步骤

MySql 怎么查出符合条件的最新的数据行?

SSM框架简单介绍

state space representation

The VUX Datetime component compute-days-function dynamically sets the date list
随机推荐
【 notes 】 the beauty of the software engineering - column 31 | software testing are responsible for the quality of products?
C. Qualification Rounds(思维,特情)
Unity beginner 5 cameras follow, border control and simple particle control (2 d)
Go 学习笔记(84)— Go 项目目录结构
Go 学习笔记(84)— Go 项目目录结构
KubeMeet Registration | The complete agenda of the "Edge Native" Online Technology Salon has been announced!
[Awards every week] The "Edge Containers" track of the Cloud Native Programming Challenge invites you to fight!
【Untitled】
What is the data directory?Why do you need it?
MYSQL unique constraint
The first immersive and high-fidelity metaverse in China, Xiyuan Universe is officially launched
New LaaS protocol Elephant Swap provides ePLATO with sustainable premium space
MySQL operation statement Daquan (detailed)
解决go环境编译不了exe
DAY17、CSRF 漏洞
Arrays and Structures
【翻译】Envoy Fundamentals,这是一个培训课程,使人们能够更快地采用Envoy Proxy。...
@ WebServlet annotations (Servlet annotations)
[SQL] at a certain correlation with a table of data update another table
海外多家权威媒体热议波场TRON:为互联网去中心化奠定基础