1.properties文件通过“.”和“=”赋值,值前不加空格,yaml通过“:”赋值,值前面加一个空格;yaml文件缩进用空格;
2.properties只支持键值对,yaml配置文件支持列表,短横线表示列表“-”;
3.properties不保证加载顺序,yaml有先后顺序;
4.properties的配置文件含中文时读取会乱码,而在yaml中不会;
注:如果你同时有properties和yaml,yaml会先执行,properties里面的属性将覆盖yaml的。
yaml:
spring:
datasource:
username: root
password: root
url: jdbc:mysql://localhost:3306/test?serverTimezone=UTC
driver-class-name: com.mysql.cj.jdbc.Driver
mybatis:
mapper-locations: classpath:mybatis/mapper/*.xml
type-aliases-package: com.test.pojo
server:
port: 8081
properties:
spring.datasource.username=root
spring.datasource.password=root
spring.datasource.url=jdbc:mysql://localhost:3306/test?serverTimezone=UTC
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
mybatis.mapper-locations=classpath:mybatis/mapper/*.xml
mybatis.type-aliases-package=com.test.pojo
server.port=8081
(推荐使用application.yaml代替application.properties,从百度搜索都是properties转yaml的小工具,反之很少就能看出谁更流行。)
本文介绍了properties和yaml配置文件的差异,包括赋值方式、支持的数据结构、加载顺序及中文处理。yaml文件使用空格缩进,支持列表,且加载顺序有保障,而properties不保证顺序且易出现中文乱码问题。推荐使用yaml,因为转换工具通常由properties转yaml,表明yaml更流行。
403

被折叠的 条评论
为什么被折叠?



