3

I am a begginer in Spring and encountered the following problem.

I have the following files:

app.properties
applicationContext.xml
web.xml

Within app.properties I have the value app.env=dev

In applicationContext.xml:

<bean class="org.springframework.web.context.support.ServletContextPropertyPlaceholderConfigurer">
        <property name="ignoreResourceNotFound" value="true" />
        <property name="location">
                <value>app.properties</value>
        </property>
 </bean>

I want to use the app.env from the properties file in web.xml like this:

<context-param>
    <param-name>ENV</param-name>
    <param-value>${app.env}</param-value>
</context-param>

I am using ${app.env} without problems in applicationContext.xml.

I have found discussions that state you can push values into web.xml from a properties file but I have also found people saying it is not possible (usually older posts).

The issue is the placeholder ${app.env} in web.xml is not replaced by the value from the properties file. Is it possible to do it? If so what am I missing.

Code Whisperer
  • 1,041
  • 8
  • 16
  • Check this link: http://stackoverflow.com/questions/12099008/how-to-include-values-from-properties-file-into-web-xml and this: http://stackoverflow.com/questions/2515954/is-it-possible-to-use-properties-files-in-web-xml-in-conjunction-with-contextco – Rana_S Dec 16 '15 at 22:58
  • @RossiRobinsion the first link provides a listener that gives a `java.lang.ClassNotFoundException` when used and the second link asks a different question and provides a different solution: it asks to define the properties file in `web.xml` as opposed to `applicationContext.xml`. My question is how to use values from properties file in `web.xml`. – Code Whisperer Dec 17 '15 at 14:43
  • I tinkered around and added the class mentioned in the first link but it does not do the trick. The placeholders don't get replaced in `web.xml` – Code Whisperer Dec 17 '15 at 16:50
  • @ code whisperer try this one: http://stackoverflow.com/questions/3250219/how-to-set-value-in-web-xml-using-property-file. See the second answer. – wSchmidt Dec 17 '15 at 21:22
  • @wSchmidt unfortunately I don't think this will work because I want to use different property files depending on environment so the actual property file name would be a variable that needs to be replaced. – Code Whisperer Dec 17 '15 at 21:43

0 Answers0