Reputation: 4228
With spring boot I'm trying to load configuration using the annotation @ConfigurationProperties("oauth2.discovery").
Everything works fine except the fact that keys of a nested map are not loaded with the configuration file content but instead they are prefixed with their respectiveindexes.
This is the code used to load the configuration :
@ConfigurationProperties("oauth2.discovery")
public class DiscoveryConfigs {
private Map<String, DiscoveryConfigs.DiscoveryConfig> config;
public Map<String, DiscoveryConfigs.DiscoveryConfig> getConfig() {
return this.config;
}
public void setConfig(Map<String, DiscoveryConfigs.DiscoveryConfig> discovery) {
this.config = discovery;
}
public static class DiscoveryConfig {
private String name;
private Map<String, String> endpoints;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public Map<String, String> getEndpoints() {
return endpoints;
}
public void setEndpoints(Map<String, String> endpoints) {
this.endpoints = endpoints;
}
}
}
This is my application.yml
oauth2:
discovery:
config:
affiliation:
name: affiliation-service
endpoints:
- public: /getPublic
- forRoleA: /getForRoleA
- forRoleB: /getForRoleB
blabla:
name: ...
And using DiscoveryConfigs to load the application.yml I got the following content:
( debugger view in IntellIj )
endpoints = {LinkedHashMap@10957} size > = 3
"0.public" -> "/getPublic"
"1.forRoleA" -> "/getForRoleA"
"2.forRoleB" -> "/getForRoleB"
Where keys are for example "0.public" instead of "public"
So I'm sure I missed something but I cannot figure what...
Upvotes: 1
Views: 3110
Reputation: 691
Checkout the description to Binding Maps on spring.io. The following should work:
oauth2:
discovery:
config:
affiliation:
name: affiliation-service
endpoints:
public: /getPublic
forRoleA: /getForRoleA
forRoleB: /getForRoleB
Upvotes: 2