I want to be able to reference environment variables in web.xml, something along the lines of this:
<context-param>
<param-name>log4jConfigLocation</param-name>
<param-value>classpath:conf/log4j-${SERVER_ENVIRONMENT}.properties</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.util.Log4j2ConfigListener</listener-class>
</listener>
<param-value>classpath:conf/log4j-${SERVER_ENVIRONMENT}.properties</param-value>
This question is similar to mine, and the most upvoted answer claims that:
If you are using Spring, you can create a bean and then directly use envvars or sysprops in Spring XML config files.
However, I don't understand how to do that. I've added this bean:
<context:property-placeholder />
<bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="serverEnvironment" value="${SERVER_ENVIRONMENT}"></property>
<property name="ignoreUnresolvablePlaceholders" value="true" />
</bean>
But I don't know if I'm doing it right, nor how to access that variable from web.xml. How should I define that bean, and how can I use its value in web.xml?