PropertySourcesPlaceholderConfigurer is the Spring component that resolves ${...} placeholders in bean definitions and @Value annotations against the Environment and any additional property sources. It replaced the older PropertyPlaceholderConfigurer, which is deprecated.
Spring Boot registers one automatically, so you rarely declare it there. In plain Spring applications, especially XML-based or Java-config ones that need strict placeholder handling, you define it yourself.
The class is a BeanFactoryPostProcessor. It runs after bean definitions are loaded but before beans are created, scans property values and @Value expressions for ${name} and replaces them with resolved values. Its sources are:
Environment, which contains system properties, environment variables and anything added with @PropertySource.setLocation(s), or a Properties object set with setProperties(...).If a placeholder cannot be resolved, startup fails with an IllegalArgumentException ("Could not resolve placeholder"), unless you opted in to ignoring it or gave a default such as ${db.port:5432}.
The bean method must be static, because the configurer is a BeanFactoryPostProcessor and has to be created before the configuration class that declares it.
With db.properties containing:
a bean can now use the values:
The missing db.timeout key falls back to its default of 30, and Spring converts the string to int.
In XML, the context namespace creates the same bean. This is equivalent to the Java version:
<context:property-placeholder> registers a PropertySourcesPlaceholderConfigurer internally, so you do not write the bean by hand. Use the explicit bean when you need to set options such as ignoreUnresolvablePlaceholders.
| Setting | Effect |
|---|---|
setLocation / setLocations | Load one or more properties files directly |
setIgnoreResourceNotFound(true) | Skip missing files instead of failing |
setIgnoreUnresolvablePlaceholders(true) | Leave unresolved ${x} untouched; needed when several configurers cooperate |
setOrder(int) | Run order when more than one configurer exists |
setLocalOverride(true) | Local properties win over the Environment |
setNullValue("@null") | Treat a given string as null |
setPlaceholderPrefix / setPlaceholderSuffix | Change the ${ and } markers |
By default, Environment values override values loaded through setLocation, so a deployment can override a file with an environment variable or a -D system property.
Spring Boot auto-configures a PropertySourcesPlaceholderConfigurer through PropertyPlaceholderAutoConfiguration. It resolves placeholders against the full Boot Environment, including application.properties, application.yml, profile files, command-line arguments and environment variables. In a Boot application:
@PropertySource for application.properties;ignoreUnresolvablePlaceholders where appropriate.@Configuration class that declares a non-static factory method. Make the @Bean method static.PropertySourcesPlaceholderConfigurer beans, the first one that cannot resolve a key fails the context. Set ignoreUnresolvablePlaceholders(true) on all but the last.@Value shows the literal ${...} text. This happens when a post-processor ran too early or the placeholder syntax is wrong; check for a missing configurer in a context that does not use Boot.Environment can read.The newer class resolves against the Spring Environment and its property sources. The old PropertyPlaceholderConfigurer only read its own properties and system properties, and it is deprecated.
No. Boot registers it automatically. Declare your own only to change defaults, such as ignoring unresolvable placeholders.
The configurer is a BeanFactoryPostProcessor and must be instantiated early. A non-static method forces Spring to create the enclosing configuration class first, before placeholders can be processed, and Spring logs a warning.
Not directly through setLocation. In Spring Boot, application.yml is read into the Environment, and placeholders then resolve from there.
PropertySourcesPlaceholderConfigurer resolves ${...} placeholders in Spring beans and @Value fields from the Environment and optional properties files. Declare it as a static @Bean in plain Spring, rely on Boot's auto-configuration otherwise, and use defaults and the ignoreUnresolvablePlaceholders option to control behaviour for missing keys.