【发布时间】:2014-08-23 17:55:51
【问题描述】:
我正在考虑在我们的 Grails 应用程序中为 ehcache 外部化某些配置参数,但我遇到了文档声称应该解决的问题。
我可能缺少一些东西。
我将 grails ehcache 插件版本 1.0.1 与 Grails 2.4.0 和 grails 缓存插件 1.1.7 一起使用。我正在使用休眠插件 3.6.10.16。
这是我的 CacheConfig.groovy 配置中的内容...
...
cacheManagerPeerProviderFactory {
peerDiscovery 'automatic'
factoryType 'rmi'
multicastGroupAddress '${ehcacheMulticastGroupAddress}'
multicastGroupPort '${ehcacheMulticastGroupPort}'
timeToLive 'site'
}
我已打开调试级日志记录,因此我可以查看它生成的 XML。这是相关的sn-p:
<cacheManagerPeerProviderFactory class='net.sf.ehcache.distribution.RMICacheManagerPeerProviderFactory'
properties="peerDiscovery=automatic,multicastGroupAddress=${ehcacheMulticastGroupAddress},multicastGroupPort=${ehcacheMulticastGroupPort},timeToLive=32"
propertySeparator=','
/>
grails ehcache 插件文档有以下注释,我希望“证明”...
(note that ${ehcacheMulticastGroupAddress} and ${ehcacheMulticastGroupPort} are an Ehcache feature that lets you use system property names as variables to be resolved at runtime)
太好了。除了我启动应用程序时它不起作用。由于以下原因,它无法创建CacheManagerPeerProvider
...
Caused by UnknownHostException: ${ehcacheMulticastGroupAddress}
->> 901 | lookupAllHostAddr in java.net.InetAddress$1
...
我有一个 myApplication-config.groovy 文件位于可访问区域中,我在为 Config.groovy 中的 grails.config.locations 分配值时指向该文件。但我不确定它是否正在努力真正插入该值。
我尝试了双引号,但它们也是一个坏主意——在解释 CacheConfig.groovy 时,它看不到我放入 myApplication-config.groovy 的配置。我确实知道它在某个时候成功地读取了该文件,因为我成功地使用它来驱动一些 Quartz 作业逻辑,因此该配置文件的位置可能不是问题。
【问题讨论】:
-
我成功地将我的
Config.groovy外部化到grails.config.locations。这个文件包含来自另一个配置的一些配置部分(例如来自DataSource.groovy)。所以,你可以尝试用同样的方式外部化你的 EhCache 设置。 -
您甚至可以在
grails.config.locations中指定外部CacheConfig.groovy即可。 -
感谢您的建议。但我意识到我做错了什么……问题在于我的阅读理解能力。 Ehcache 正在寻找
system properties而不是上下文配置的东西。
标签: caching grails config ehcache externalizing