对于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
如果您参考Spring Boot参考文档中的“使用YAML而不是属性”一节,它说,如果您的类路径上有SnakeYAML库,则Spring Boot应该自动选择它。
话虽如此,它也指出
如果您使用“启动程序POM”,SnakeYAML将通过spring-boot-starter自动提供
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句