将ehcache.xml外部化以使用外部属性文件中的属性

Tri*_*pti 5 java spring hibernate ehcache second-level-cache

我想将属性占位符放在ehcache.xml文件中(如$ {}),以便可以在运行时从外部属性文件(.properties)替换值.就像是:

ehcache.xml(在类路径中):

 <defaultCache
maxElementsInMemory="20000"
eternal="false"
timeToIdleSeconds="${default_TTI}"
timeToLiveSeconds="86400"
overflowToDisk="true"
... />
Run Code Online (Sandbox Code Playgroud)

ehcache.properties(在war/classpath之外):

...
default_TTI=21600
...
Run Code Online (Sandbox Code Playgroud)

目的是能够更改缓存配置,而无需重建应用程序.Spring的PropertyPlaceHolder只适用于我不想要的ehcache的Spring bean definiton(需要将ehcache.xml保存为文件)

这里有类似的帖子,但没有任何东西让我解决.我一直在寻找一个星期!!

我使用Spring 2.5.6,Hibernate 3.2.6和Ehcache 2.4.6

任何帮助或想法是非常Appriciated !!

非常感谢,Tripti.

bra*_*rry 0

如果您只想在启动时从磁盘读取配置,您可以在 EHCache 2.5 中执行以下操作:

InputStream fis = 
    new FileInputStream(new File("src/config/ehcache.xml").getAbsolutePath());
try 
{
  CacheManager manager = new CacheManager(fis);
} 
finally 
{
  fis.close();
}
Run Code Online (Sandbox Code Playgroud)