初始化缓存时出现异常导致 "grails run-app" 失败

exception when initialising cache causes "grails run-app" to fail

在我的 Grails 2.5.4 应用程序中,我安装了以下插件

compile ":cache:1.1.8"
runtime ":cache-ehcache:1.0.5"

当我运行grails run-app时,我在启动时得到以下错误

java.lang.NullPointerException
    at grails.plugin.cache.ehcache.GrailsEhCacheManagerFactoryBean$ReloadableCacheManager.rebuild(GrailsEhCacheManagerFactoryBean.java:171)
    at grails.plugin.cache.ehcache.EhcacheConfigLoader.reload(EhcacheConfigLoader.groovy:63)
    at grails.plugin.cache.ConfigLoader.reload(ConfigLoader.groovy:42)
    at CacheGrailsPlugin.reloadCaches(CacheGrailsPlugin.groovy:202)
    at CacheGrailsPlugin$_closure3.doCall(CacheGrailsPlugin.groovy:158)

如果我构建 WAR 并查看 lib 目录,它包含以下两个依赖项:

根据this issue中的建议,我排除了BuildConfig

中的传递ehcache-core依赖
runtime (":hibernate:3.6.10.18") { 
  excludes "ehcache-core" 
}

如果我重建 WAR,ehcache-core JAR 排除的,但是当我 运行 grails run-app。我怀疑问题的原因是 ehcache 依赖项,但我不知道应该使用哪个 JAR。

升级到 hibernate 3.6.10.19 似乎解决了这个问题。当我构建 WAR 时,包含以下 ehcache 依赖项:

  • ehcache-2.9.0.jar
  • hibernate-ehcache-3.6.10.Final.jar