zoukankan      html  css  js  c++  java
  • yml、properties文件配置

    spring:
      datasource:
        url: jdbc:mysql://127.0.0.1:3306/wxdd?serverTimezone=GMT%2B8&useUnicode=true&characterEncoding=utf-8&useSSL=false
        driver-class-name: com.mysql.cj.jdbc.Driver
        username: root
        password: 123456
      jpa:
        show-sql: true
    
    
    server:
      #打的war包名
      context-path: /sell

    1.yml支持多文档块方式

    server:
      port: 8081
    spring:
      profiles:
        active: prod
    
    ---
    server:
      port: 8083
    spring:
      profiles: dev
    
    
    ---
    
    server:
      port: 8084
    spring:
      profiles: prod  #指定属于哪个环境

    2.properties配置文件

    properties配置文件中占位符

    1、随机数

    ${random.value}、${random.int}、${random.long}
    ${random.int(10)}、${random.int[1024,65536]}

    2、占位符获取之前配置的值,如果没有可以是用:指定默认值

    person.last-name=张三${random.uuid}
    person.age=${random.int}
    person.birth=2017/12/15
    person.boss=false
    person.maps.k1=v1
    person.maps.k2=14
    person.lists=a,b,c
    person.dog.name=${person.hello:hello}_dog   //若是前面的配置没有取到person.hello的值,则默认为hello
    person.dog.age=15

    3.配置文件加载顺序是根据文件的位置来定义的

    –file:./config/
    
    –file:./
    
    –classpath:/config/
    
    –classpath:/
    
    优先级由高到底,高优先级的配置会覆盖低优先级的配置;
    
    SpringBoot会从这四个位置全部加载主配置文件;**互补配置**;
  • 相关阅读:
    [k8s微服务作业]-day2-Docker基础
    运维常用命令记录
    【莫比乌斯反演】学习笔记
    2021牛客OI赛前集训营-提高组(第一场)
    NOIP 计划 · 模拟赛 #10
    2021牛客OI赛前集训营-提高组(第二场)
    10.5 模拟赛题解报告
    组合数学
    线段树合并
    2021, 9,26 模拟赛
  • 原文地址:https://www.cnblogs.com/gxlaqj/p/11656563.html
Copyright © 2011-2022 走看看