[Spring Error] Could not resolve placeholder

Background

Running the Spring Boot project occurs an error.

Error Info

Caused by: java.lang.IllegalArgumentException: Could not resolve placeholder 'spring.datasource.druid.initialSize' in value "${spring.datasource.druid.initialSize}"
at org.springframework.util.PropertyPlaceholderHelper.parseStringValue(PropertyPlaceholderHelper.java:178)
... 97 common frames omitted

Solutions

1. Check that the property you need exists in a configuration file. Find out in which configuration file your injected property is.

2. Check whether the property spring.profiles.active value is correct in application.yml. Make sure the active profile is in your project.

3. Check whether your injected property exists in application.yml (or application.properties) and the active profile application-xxx.yml (or application-xxx.properties).

Reasons

The value of the property spring.profiles.active in my application.yml is spring.profiles.active=pro, but I don’t have the application-pro.yml file. The property’s value spring.profiles.active=pro should update to prod.