1

I defined an environment variable in web.xml as below..

<env-entry>
    <env-entry-name>appName</env-entry-name>
    <env-entry-type>java.lang.String</env-entry-type>
    <env-entry-value>myApp</env-entry-value>
</env-entry>

Now I want to access this value in spring mvc resources tag as below.

<mvc:resources order="-10" mapping="/robots.txt" 
        location="${jboss.home.dir}/${appName}/robots.txt" />

But the variable ${appName} is not resolving. Can you please help me out on how to read the environment entry in spring xml files?

sp.prakash
  • 21
  • 3
  • possible duplicate of [Read an environment variable from applicationContext.xml](http://stackoverflow.com/questions/12391474/read-an-environment-variable-from-applicationcontext-xml) – Ankur Singhal Jan 13 '15 at 04:43
  • Which version of Spring are you using? – M. Deinum Jan 13 '15 at 06:36
  • @ankur-singhal - I saw the post. It suggests to define JNDI lookup and refer the JNDI entry. But I am looking for a solution where I can access the variable like JBOSS environment properties -- ${jboss.home.dir}.. – sp.prakash Jan 13 '15 at 08:34
  • @M.Deinum - I am using spring 3.2.9 version. – sp.prakash Jan 13 '15 at 08:34
  • Your question states clearly that yuo want the `${appName}` resolved so which is it? Make sure you have a `` in your configuration. You don't need to load a file but you need it for placeholder replacement, especially for those not in the system properties or system environment. – M. Deinum Jan 13 '15 at 08:48
  • @M.Deinum - Thanks for your suggestion. I will give a try with adding the spring property-placeholder tag and let you know how it goes.. – sp.prakash Jan 14 '15 at 09:49
  • @M.Deinum - I added the in my applicationContext.xml file. But still it didn't work.. – sp.prakash Jan 16 '15 at 10:36
  • Make sure that the `` is in the same context as `` it will only replace values in the context it is defined in. – M. Deinum Jan 16 '15 at 10:40
  • @M.Denium - I suppose both are in same context, but I will double check and confirm. – sp.prakash Jan 16 '15 at 11:26

0 Answers0