Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Externarlize ehcache.xml to use properties from external properties file

I want to place property place holders in the ehcache.xml file (like ${}) so that the values can be replaced from external properties file (.properties) at runtime. Something like:

ehcache.xml (in classpath):

 <defaultCache
maxElementsInMemory="20000"
eternal="false"
timeToIdleSeconds="${default_TTI}"
timeToLiveSeconds="86400"
overflowToDisk="true"
... />

ehcache.properties (outside of the war/classpath):

...
default_TTI=21600
...

The purpose is to be able to change the cache configuration without the need to rebuild the app. Spring's PropertyPlaceHolder will only work with Spring bean definiton for ehcache which I dont want (need to keep the ehcache.xml as a file)

There are similar posts here but nothing got me to solution. I've been searching for a week now!!

Im using Spring 2.5.6,Hibernate 3.2.6 and Ehcache 2.4.6

Any help or idea is greatly Appriciated!!

Thanks a lot, Tripti.

like image 555
Tripti Avatar asked Mar 23 '12 21:03

Tripti


1 Answers

As a workaroud solution you can set property values to system scope (System.setProperty(...)). EhCahe uses these properties to resolve placeholders during parsing its configuration file.

like image 129
svaor Avatar answered Sep 28 '22 04:09

svaor