When prefix is missing for config properties, make the map to empty and not null

Dendin :

Currently, if my application.yml does not include the mapping of a property, my config class does not initializes the map and leaves it as null instead of empty. How can i make it be empty if no mapping is found?

@Configuration
@ConfigurationProperties(prefix = "someMapping")
@EnableConfigurationProperties
@Getter
@Setter
public class HttpLoggingLevelProperties {
    private Map<String, String> loggingLevelMap;
}
Steve Benett :

Just initialize the map yourself. In the default constructor or directly on the field.

private Map<String, String> loggingLevelMap = new HashMap<>();

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=27086&siteId=1