Spring Boot 中 properties 配置与 yaml 配置的区别以及书写方式

properties 配置与 yaml 配置的两大区别

  • yaml 配置是有序的,properties 配置是无序的

  • 自定义的 yaml 目前暂时不支持使用注解直接注入到 Spring Boot 项目中

yaml 文件的书写格式如下图:

server:
  port: 8081
  servlet:
    context-path: /you
redis:
  port: 6379
  hosts:
    - 192.168.66.128
    - 192.168.66.129
    - 192.168.66.130
    - 192.168.66.131
  redisList:
    - port: 6379
      host: 192.168.66.66
    - port: 6380
      host: 192.168.66.67

注意:

  • 严格按照缩进层次来写,且有顺序。

  • 冒号后面有一个空格,如port: 8081

对比一下,properties 文件的书写如下:

# 修改服务器端口号
server.port = 8081
# 修改上下文路径
server.servlet.context-path=/you
# 配置 Tomcat URL 编码
server.tomcat.accesslog.encoding=UTF-8

每天学习一点点,每天进步一点点。

posted @ 2020-05-30 17:17  爱吃西瓜的番茄酱  阅读(468)  评论(0编辑  收藏  举报