Spring application.yaml have dash in key

Viewed 8757

I want to create @Bean ExampleProperties.java and want to automatically get key/value in application.yaml, for example:

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

How to create a parameter equals to the key in application.yml??

2 Answers

If you are like me and your property looks like this :

my-config-map.key

Then you want:

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

      private String key;
  
      // getter/setter

}
Related