Bug faced in Spring Boot 2.2.10. ConfigurationProperties
fails to map data to List of objects if data is divided between several property sources.
Steps to reproduce: Running an application with Spring component and ConfigurationProperties
annotation which maps properties to List of objects, for example:
@Component
@ConfigurationProperties(prefix = "rtcp.mgr.turn")
public class IceServiceProperties {
private List<IceServer> iceServers = new ArrayList<>();
public List<IceServer> getIceServers() {
return iceServers;
}
public void setIceServers(List<IceServer> iceServers) {
this.iceServers = iceServers;
}
}
public class IceServer {
private String[] urls;
private String sharedSecret;
public String[] getUrls() {
return urls;
}
public IceServer setUrls(String[] urls) {
this.urls = urls;
return this;
}
public String getSharedSecret() {
return sharedSecret;
}
public IceServer setSharedSecret(String sharedSecret) {
this.sharedSecret = sharedSecret;
return this;
}
}
When we divide data for ConfigurationProperties between several sources (for example env variables and application.properties) spring ignores one of them.
content of application.properties file:
rtcp.mgr.turn.iceservers[0].sharedsecret=secret
env vars:
RTCP_MGR_TURN_ICESERVERS_0_URLS=turn-prod.rtcp.com
After application start iceServers
in IceServicePropertie
contain an object with sharedSecret=null
and urls=[turn-prod.rtcp.com]
Comment From: wilkinsona
This is working as designed. When binding to a list, the values are all bound from a single property source. The sources are examined in priority order and the first property source that contains an item in the list is used to bind all of the list's items.