Spring Boot properties in 'application.yml' not loading from JUnit Test

前端 未结 10 532
野趣味
野趣味 2021-01-31 13:59

What am I doing wrong? I\'m using this little standalone App which runs and finds my src/main/resources/config/application.yml. The same configuration doesn\'t work

10条回答
  •  佛祖请我去吃肉
    2021-01-31 14:59

    In my case I was trying to test a library without a @SpringBootApp declared in the regular app classpath, but I do have one in my test context. After debugging my way through the Spring Boot initialization process, I discovered that Spring Boot's YamlPropertySourceLoader (as of 1.5.2.RELEASE) will not load YAML properties unless org.yaml.snakeyaml.Yaml is on the classpath. The solution for me was to add snakeyaml as a test dependency in my POM:

        
            org.yaml
            snakeyaml
            1.19
            test
        
    

提交回复
热议问题