Spring application.yaml有密钥破解

时间:2017-07-17 10:35:58

标签: spring annotations

我想创建@Bean ExampleProperties.java并希望在application.yaml中自动获取键/值,例如:

@ConfigurationProperties("server")
public class ExampleProperties {
    private String context-path; //this would be a mistake, cause you could not have "-" in parameter name,
}

如何创建参数等于application.yml ??

中的键

2 个答案:

答案 0 :(得分:0)

根据enter image description here属性,破折号将在java中表示为

@ConfigurationProperties("server")
public class ExampleProperties {
  private String contextPath;
}

答案 1 :(得分:0)

如果你和我一样,你的财产是这样的:

my-config-map.key

那么你想要:

@ConfigurationProperties(prefix = "my-config-map")
public class Prop {

      private String key;
  
      // getter/setter

}