caching - Grails ehcache和外部化配置

标签 caching grails config ehcache externalizing

我正在外部查看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。以下是相关代码段:
<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中的grails.config.locations分配值时指向的可访问区域中有一个Config.groovy文件。但是我不确定它是否会为实现这一值(value)做任何努力。

我尝试使用双引号,但它们也是一个坏主意-在解释CacheConfig.groovy时,看不到我在myApplication-config.groovy中添加的配置。我确实知道它在某个时刻成功读取了该文件,因为我成功地使用它来驱动某些Quartz作业逻辑,因此该配置文件的位置可能不是问题。

最佳答案

答案是我需要为ehcache设置系统属性以进行查找。使用Grails配置文件(例如myApplication-config.groovy)是完全不正确的。
CacheConfig.groovy文件以及它生成的XML是正确的。因此,问题就来了,首先如何正确设置它寻找的属性?

我正在部署到Tomcat。对于Tomcat,在setenv.bat文件(或* nix上的setenv.sh)中设置系统属性最有意义。

我创建了setenv.bat,将以下内容放入其中

set CATALINA_OPTS=%CATALINA_OPTS% -DehcacheMulticastGroupAddress=230.0.0.1 -DehcacheMulticastGroupPort=4446 -DehcachePeerListenerPort=40001

...而且有效。 Ehcache能够找到系统属性并适当启动所有内容。

tl; dr:系统属性!= grails应用程序配置

关于caching - Grails ehcache和外部化配置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24539636/

相关文章:

ruby - 没有 config.ru 的启动 Rack 服务器?

c# - 强制 IConfigurationBuilder.Bind() 在绑定(bind)对象失败时抛出错误

c# - 按 Url 输出缓存(路由)ASP.NET 4

ruby-on-rails - Rails 3.2 的缓存未命中以及开发中的页面缓存 - 还有其他人吗?

java - 在 Ignite 缓存中插入数据时出现以下错误?

grails - 最适合 Multi-Tenancy /多模板 SAAS 应用程序的 Web 框架

grails - Grails:在插件中添加动态方法

eclipse - 如何使用Mongo为Birt编写表达式?

android - 缓存路由在 Skmaps 上被清除

configuration - 使用 systemd 配置风格的 Docker 配置