Spring Boot: Load @Value from YAML file

前端 未结 6 1832
一整个雨季
一整个雨季 2020-12-28 14:23

I need to load a property from a .yml file, which contains the path to a folder where the application can read files from.

I\'m using the following code

6条回答
  •  感动是毒
    2020-12-28 14:45

    I've got that issue Caused by: java.lang.IllegalArgumentException: Could not resolve placeholder cause I've set test spring boot profile in properties.yaml. Spring can't find properties for test profile when run app with no profile.

    So remove spring boot profile from properties or yaml or run app with enabled profile.

    Configuration file example is below:

    @Configuration
    public class AppConfig {
      @Value("${prop.foo}")
      private String foo;
      @Value("${prop.bar}")
      private String bar;
    
      @Bean
      BeanExample beanExample() {
        return new BeanExample(foo, bar);
      }
    }
    

提交回复
热议问题