【发布时间】:2015-10-26 16:18:51
【问题描述】:
Springboot 有什么特别要说的,要考虑配置 yaml 文件而不是属性文件吗?我在项目中使用 Maven 和 Springboot,如果我将文件 application.properties 放在资源文件中,Springboot 会自动识别配置。
但是,仅用 yml 文件替换属性文件是行不通的,该文件不再考虑在内。
有什么要添加到 SpringBoot 以使用 yml 文件吗?
两个文件下方:
application.properties:
# THYMELEAF (ThymeleafAutoConfiguration)
spring.thymeleaf.check-template-location=true
spring.thymeleaf.prefix=/WEB-INF/views/
spring.thymeleaf.suffix=.html
spring.thymeleaf.mode=LEGACYHTML5
spring.thymeleaf.encoding=UTF-8
spring.thymeleaf.content-type=text/html
spring.thymeleaf.cache=false
和application.yml
spring:
profiles:
active: ${dario.environment:dev}
thymeleaf:
check-template-location: true
thymeleaf.prefix: /WEB-INF/views/
thymeleaf.suffix: .html
thymeleaf.mode: LEGACYHTML5
spring.thymeleaf.encoding: UTF-8
spring.thymeleaf.content-type: text/html
cache: false
【问题讨论】:
-
嘿,你是怎么在你的 yml 文件中写 active: ${dario.environment:dev} 的?你的 yml 文件是从哪里读取的?
-
一个系统属性,即来自命令行-Ddario.environment=prod,如果我没有指定属性,默认会采用dev。希望这会有所帮助
标签: java spring spring-boot