spring boot 配置文件佔位符和多環境配置 [六]

配置文件佔位符

person.last-name=zhangsan
person.age=${random.int}
person.birth=2017/12/15
person.boss=false
person.maps.k1=v1
person.maps.k2=#{person.last-name:zhangsan}
person.lists=a,b,c

${random.int} 能夠指定一些隨機數java

{person.last-name:zhangsan} 能夠引用配置文件的配置內容,:後面表明如何找不到引用,那麼就用後面zhangsan。

多環境配置

這個spring boot自己就自我支持,只需知道怎麼用就好。spring

我建立了上面兩個文件。app

在application.properties 中:dom

spring.profiles.active=dev

application-dev.properties:命令行

server.port=8083

application-prod.properties:code

server.port=8082

由於上面激活的是dev,那麼運行後:server

在yml配置文件中,你須要這樣寫:blog

server:
  port: 8082
spring:
  profiles:
    active: dev

---
server:
  port: 8083
spring:
  profiles:dev
---
server:
  port: 8082
spring:
  profiles:prod

一樣命令行也能夠實現,並且是最高優先級。io

在配置中:ast

實際上其真實運行參數爲:--spring-profiles-avtive=prod.

全名是:java -jar xxx.jar --spring-profiles-avtive=prod

相關文章
相關標籤/搜索