0

I would like to use a Envriomental variable in the location of property-placeholder but I don't get it:

I tried in this way:

<context:property-placeholder location="${CATALINA_HOME}/conf/database.properties" order="0"/>

but I get this error

org.springframework.beans.factory.BeanInitializationException: Could not load properties; nested exception is java.io.FileNotFoundException: Could not open ServletContext resource [/${CATALINA_HOME}/conf/database.properties]

Also, I don't find documentation about use envriomental variables in the context configuration or property-placeholder.

Kind regards.

Josema
  • 445
  • 2
  • 6
  • 22

3 Answers3

1

I think you should do it like this:

<context:property-placeholder location="#{ systemProperties['CATALINA_HOME'] }/conf/database.properties"/>

If I didn't understand you wrong.

Jaiwo99
  • 9,687
  • 3
  • 36
  • 53
  • I'm getting the same error. It looks that doesn't translate the expression. Could not load properties; nested exception is java.io.FileNotFoundException: Could not open ServletContext resource [/#{systemProperties['CATALINA_HOME']}/conf/database.properties]. – Josema Sep 04 '13 at 11:58
  • @Josema do you have `CATALINA_HOME` defined somewhere? – Jaiwo99 Sep 04 '13 at 12:33
  • yes, it's an envriomental variable of the linux system. so when I do echo $CATALINA_HOME it's shown – Josema Sep 04 '13 at 12:58
  • I used ${catalina.home} and this worked :). When I use your expression {systemProperties['CATALINA_HOME'] it looks to work between tags, because I get a empty string in the error instead of the expression, I think I don't have definied CATLINA_HOME when I execute from eclipse. – Josema Sep 06 '13 at 09:46
1

I used:

and I listened that this work for tomcat 6.0 or more.

Josema
  • 445
  • 2
  • 6
  • 22
0

You can use following way as well, I'm using this in my application

<context:property-placeholder location="file:${env.CATALINA_HOME}/conf/database.properties"/>
Martin
  • 2,135
  • 8
  • 39
  • 42