Working on a legacy Spring based application (Spring 4.3), I have a strange behavior: environment variables are not resolved by Spring.
For example I have this environment variable: HOST_SERVICE_BASE_URL
, when I refer to it in the application with ${host.service.base.url}
the property is not resolved and the application fails during start up.
Caused by: java.lang.IllegalArgumentException: Could not resolve placeholder 'host.service.base.url' in value "${host.service.base.url}
I defined these beans for property resolution:
@Bean
public PropertiesFactoryBean applicationProperties( ResourceLoader resourceLoader ) {
PropertiesFactoryBean propertiesFactory = new PropertiesFactoryBean();
propertiesFactory.setLocations( resourceLoader.getResource( "/WEB-INF/config/application.properties" ),
resourceLoader.getResource( "/WEB-INF/config/application-dev.properties" ) );
return propertiesFactory;
}
And
<bean id="dataConfigPropertyConfigurer"
class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="ignoreResourceNotFound" value="true"/>
<property name="searchSystemEnvironment" value="true"/>
<property name="systemPropertiesModeName" value="SYSTEM_PROPERTIES_MODE_OVERRIDE"/>
<property name="properties" ref="applicationProperties"/>
</bean>