Java 如何在Spring boot中用yml文件替换属性文件

Java 如何在Spring boot中用yml文件替换属性文件,java,spring,spring-boot,Java,Spring,Spring Boot,是否有什么特别的话要对Springboot说,以作为配置yaml文件而不是属性文件考虑?我在项目中使用Maven和Springboot,如果我将application.properties文件放在资源文件中,Springboot会自动识别配置 但是,仅仅用yml文件替换属性文件是不起作用的,该文件不再考虑 有什么要补充的吗?比如说SpringBoot使用yml文件 以下两个文件: application.properties: # THYMELEAF (ThymeleafAutoConfigur

是否有什么特别的话要对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
和应用程序.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而不是属性”一节,它会说Spring Boot应该自动选择它,因为您的类路径上有SnakeYAML库

话虽如此,它也指出

如果您使用“starter POMs”,SnakeYAML将通过以下方式自动提供: 弹簧靴起动器


谢谢,我在类路径上发现了SnakeYAML,我刚刚发现了问题。我的YML文件的格式不正确。我在重复“百里香”这个词。修正:)嘿,你是如何在你的yml文件中写活动:${dario.environment:dev}的?您的yml文件从何处读取此内容?系统属性,即从命令行-Ddario.environment=prod,如果我未指定任何属性,默认情况下将使用dev。希望这有帮助