当前位置:网站首页>05全局配置文件application.properties详解
05全局配置文件application.properties详解
2022-07-30 04:15:00 【m0_54861649】
Spring Boot 提供了大量的自动配置,极大地简化了spring 应用的开发过程,当用户创建了一个 Spring Boot 项目后,即使不进行任何配置,该项目也能顺利的运行起来。当然,用户也可以根据自身的需要使用配置文件修改 Spring Boot 的默认设置。
SpringBoot 默认使用以下 2 种全局的配置文件,其文件名是固定的。
- application.properties
- application.yml
application.properties与 application.yaml都可以作为Spring Boot的配置文件,只是书写格式不同而已,在 Spring Boot 启动时被自动读取。当然也可以同时使用,但同级目录下读取的顺序是先读取application.properties,读取application.yaml。该配置文件的存放路径如下图所示。

本节我们将详细介绍 application.properties的语法及使用
下面是一个简单的 application.properties属性配置文件。
server.port=8080
properties 语法
properties的语法如下:
- 使用properties的key=value形式
- 使用层级递进关系。
- 从最高层到最低层逐个低级,中间使用点"."间隔
例如:
server.address=localhost/170.20.10.112 #可以写IP或域名 server.port=80 #表示监听的80端口,默认是8080 spring.datasource.driver-class-name=com.mysql.jdbc.Driver #数据库驱动 spring.datasource.url=jdbc:mysql://localhost:3306/cqyddx?useUnicode=true&characterEncoding=UTF-8&allowPublicKeyRetrieval=true&useSSL=false&serverTimezone=Asia/Shanghai spring.datasource.username=root spring.datasource.password=root
properties常用写法
properties支持以下三种数据结构:
- 对象:键值对的集合
- 数组:一组按次序排列的值
- 字面量:单个的、不可拆分的值
properties字面量写法
字面量是指单个的,不可拆分的值,例如:数字、字符串、布尔值、以及日期等。
在 properties中,使用“key[=]value**”**的形式表示一对键值对(空格不能省略),如 name=“xiatian”,age=32。
字面量直接写在键值对的“value”中即可,且默认情况下字符串是不需要使用单引号或双引号的。
name=“xiatian”age=32
若字符串使用单引号,则会转义特殊字符。
name=“zhangsan ’ **'**lisi”输出结果为:zhangsan lisi
若字符串使用单引号,则会转义特殊字符。
name=“zhangsan lisi”输出结果为:
- zhangsan
- lisi
properties对象写法
在 properties中,对象可能包含多个属性,每一个属性都是一对键值对。
properties 为对象提供了 以下写法:
使用递进表示对象与属性的层级关系。
user.name=“xiatian”user.age=32
properties数组写法
properties 使用[x]表示数组中的元素,普通写法如下:
user.books[0]=“biancheng0”user.books[1]=“biancheng1”
user.books[2]=“biancheng2”
user.books[3]=“biancheng3”
复合结构
以上三种数据结构可以任意组合使用,以实现不同的用户需求,例如:
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”
先自我介绍一下,小编13年上师交大毕业,曾经在小公司待过,去过华为OPPO等大厂,18年进入阿里,直到现在。
深知大多数初中级java工程师,想要提示技能,往往是需要自己摸索成长或是报班学习,但对于培训机构动则近万元的学费,着实压力不小。自己不成体系的自学效率很低又漫长,而且容易碰到天花板技术停止不前。
因此我收集了一份《java开发全套学习资料》送给大家,初衷也很简单,就是洗碗帮助到想自学又不知道该从何学起的朋友,同时减轻大家的负担。
点击下方名片,领取java开发全套学习资料
边栏推荐
- redis分布式锁的原子保证
- ospf map
- How to Effectively Conduct Retrospective Meetings (Part 1)?
- Solve the problem of compiling and installing gdb-10.1 unistd.h:663:3: error: #error “Please include config.h first.”
- Pytorch框架学习记录5——DataLoader的使用
- High Concurrency Framework Disruptor
- Mysql版本升级,直接复制Data文件,查询特别慢
- SQL Server data type conversion function cast () and convert () explanation
- 验证addShutdownHook钩子生效
- spicy (two) unit hooks
猜你喜欢

Reverse Analysis Practice 2

Has been empty, a straightforward, continue to copy the top off!

Go书籍大全-从初级到高级以及Web开发

Pytorch framework learning record 5 - the use of DataLoader

ospf 导图

Pytorch framework learning record 7 - convolutional layer

MySQL 字符串拼接 - 多种字符串拼接实战案例

forward与redirect的区别

High Concurrency Framework Disruptor

PyG builds R-GCN to realize node classification
随机推荐
Mini Program Graduation Works WeChat Points Mall Mini Program Graduation Design Finished Work (7) Interim Inspection Report
[ 云原生之谜 ] 云原生背景 && 定义 && 相关技术详解?
mysql structure, index details
cv2.polylines
ospf 导图
MySQL 字符串拼接 - 多种字符串拼接实战案例
弘玑再度入围Gartner 2022 RPA魔力象限并实现位置大幅跃升
The underlying mechanism of the function
Pytorch framework to study record 6 - the torch. Nn. The Module and the torch nn. Functional. The use of conv2d
QT(39)-vs开发qt程序提示无法打开源文件
JQ source code analysis (environment)
New LaaS protocol Elephant Swap provides ePLATO with sustainable premium space
Charles replaces the interface response information
【驱动】udev设置GPIO加载后所有者、所属组和权限
骁龙7系芯片表现如何?Reno8 Pro佐证新一代神U
逆向理论知识3【UI修改篇】
高并发框架 Disruptor
Taobao/Tmall get the list of sold product orders API
Thymeleaf简介
ospf 综合实验(重发布,特殊区域)