spring boot simplifies a lot of operations, but not when injecting Map types.
can be implemented using @ ConfigurationProperties, but with a little more complexity. Setting the
Map value to a json string is also possible, but it reduces readability.
is there any way to inject Map into @ value?
expect the following way
@Value("${my.map}")
private Map<String, String> map;
but the error message Could not resolve placeholder "my.map" in value "${my.map}"
application-dev.yml
my:
string: string_value
map:
name: name_value
age: age_value
Application
@SpringBootApplication
public class Application extends SpringBootServletInitializer implements ApplicationRunner {
@Autowired
private MyMap myMap;
@Value("${my.string}")
private String stringValue;
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
@Override
public void run(ApplicationArguments args) throws Exception {
System.out.println(stringValue);
System.out.println(myMap);
}
}