SpringBoot uses @Value to read properties from YAML file

There is the following configuration in YAML

paypal:
  mode:live

In the class, read through the @Value property

@Value("${paypal.mode}")
private String mode;

When the program runs, it reports an error

Caused by: java.lang.IllegalArgumentException: Could not resolve placeholder 'paypal.mode' in string value "${paypal.mode}"

 

The root of the problem is that the configuration does not conform to the YAML file format requirements. One less space between mode and live

paypal:
  mode: live

After adding spaces, it works fine.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326514004&siteId=291194637