We are using Spring Boot 2.
We want to use the refresh mechanism of Spring Boot, but due to a bug we can't use @Configuration
, hence we are forced to replace all theses by @Value
in combination with @RefreshScope
.
So we used that:
@Configuration
@RefreshScope
public class MyConfig {
@Value("${myMap}")
private Map<String, String> myMap;
}
With that YAML file for example:
myMaps:
key1: Value
key2: Another Value
But we get an error out of it:
Error creating bean with name 'scopedTarget.myMap': Unsatisfied dependency expressed through field 'mapMap'; nested exception is org.springframework.beans.ConversionNotSupportedException: Failed to convert value of type 'java.lang.String' to required type 'java.util.Map'; nested exception is java.lang.IllegalStateException: Cannot convert value of type 'java.lang.String' to required type 'java.util.Map': no matching editors or conversion strategy found
We found already other thread with a similar topic:
- How to fill HashMap from java property file with Spring @Value
- How to inject a Map using the @Value Spring Annotation?
But we can't use other kind of property bindings, as we are deploying this app into kubernetes and use the config maps of kubernetes.
So we wonder, if there is any other chance to get @Value
working together with Map