我想在 ehcache.xml 文件中放置属性占位符(如 ${}),以便可以在运行时从外部属性文件 (.properties) 替换这些值。 像这样的东西:
ehcache.xml(在类路径中):
<defaultCache maxElementsInMemory="20000" eternal="false" timeToIdleSeconds="${default_TTI}" timeToLiveSeconds="86400" overflowToDisk="true" ... />
ehcache.properties(在 war/classpath 之外):
... default_TTI=21600 ...
目的是无需重新构建应用程序即可更改缓存配置。 Spring 的 PropertyPlaceHolder 仅适用于我不想要的 ehcache 的 Spring bean 定义(需要将 ehcache.xml 保留为文件)
这里有类似的帖子,但我没有找到解决方案。我已经搜索了一个星期了!!
我正在使用 Spring 2.5.6、Hibernate 3.2.6 和 Ehcache 2.4.6
非常感谢任何帮助或想法!!
非常感谢, 特里普蒂。
最佳答案
作为变通解决方案,您可以将属性值设置为系统范围 (System.setProperty(...))。 EhCahe 在解析其配置文件时使用这些属性来解析占位符。
关于java - 外部化 ehcache.xml 以使用来自外部属性文件的属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9846503/