Spring boot @ value loads yml map data

Using @ value to automatically inject attribute values in

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);

    }
}
Apr.22,2022

my:
  string: string_value
  map:
    name: name_value
    age: age_value

map must be an object in writing my.map in this way. If you want to get Map this way,

correct writing

  

@ value does not seem to be able to inject map.
must use @ ConfigurationProperties, which

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1b37f17-4d771.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1b37f17-4d771.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?