当前位置:网站首页>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
边栏推荐
- 机器学习:知道通过低方差过滤实现降维过程
- JQ源码分析(环境处理)
- 05全局配置文件application.properties详解
- labelme的使用技巧
- The first immersive and high-fidelity metaverse in China, Xiyuan Universe is officially launched
- [Driver] udev sets the owner, group and permissions after GPIO is loaded
- handler+message【消息机制】
- PyG builds R-GCN to realize node classification
- 【周周有奖】云原生编程挑战赛“边缘容器”赛道邀你来战!
- 数据库概论 - MySQL的简单介绍
猜你喜欢

Data Lake: Data Integration Tool DataX

PyG builds R-GCN to realize node classification

Thymeleaf简介

MySQL installation error solution

Azure 开发者新闻快讯丨开发者7月大事记一览

2.5快速排序

@WebServlet注解(Servlet注解)

The implementation and basic operation of sub-database sub-table, ER table, global table, fragmentation rules, global sequence, etc. in MyCat

The first immersive and high-fidelity metaverse in China, Xiyuan Universe is officially launched

Usage of exists in sql
随机推荐
unity初学5 摄像机跟随,边界控制以及简单的粒子控制(2d)
2.5快速排序
Chapter8 Support Vector Machines
The underlying mechanism of the function
How does the Snapdragon 7 series chip perform?Reno8 Pro proves a new generation of God U
小程序 wx.miniProgram.navigateTo 跳转地址不能是tabbar地址
Notes on "The Law of Construction"---Chapter 10 Typical Users and Scenarios
[SQL] at a certain correlation with a table of data update another table
See you in shenzhen!Cloud native to accelerate the application building special: see cloud native FinOps, SRE, high-performance computing scenario best practices
权值线段树+线段树分裂/合并+CF1659D
KubeMeet Registration | The complete agenda of the "Edge Native" Online Technology Salon has been announced!
C. Travelling Salesman and Special Numbers (二进制 + 组合数)
LeetCode 114. Expand Binary Tree into Linked List (One Question Three Eats)
handler+message【消息机制】
VUX Datetime 组件compute-days-function动态设置日期列表
Introduction to database - MySQL simple introduction
数据库概论 - MySQL的简单介绍
2.6归并排序
swagger使用教程——快速使用swagger
golang中如何比较struct,slice,map是否相等以及几种对比方法的区别