This is a brief note about ${…} placeholder resolution in Spring.
Tested with Spring 4.0 ~ 4.2.

The simplest way I’ve found is to define a bean of PropertySourcesPlaceholderConfigurer class: this bean will resolve placeholder using every PropertySource that takes part to Spring’s Environment (for example, JVM system properties, system environment variables, or custom ones like an external app.properties file).

The bean definition could be the following, with the “static” modifier to allow early bean instantiation.

@Configuration
public class GeneralConfiguration {
  @Bean
  public static PropertySourcesPlaceholderConfigurer propertySourcesPlaceholderConfigurer() {
    return new PropertySourcesPlaceholderConfigurer();
  }
}
Annunci