3

创建空grails项目

grails create-app foo

已修改BuildConfig.groovy,未注释

inherits("global") {  
  // uncomment to disable ehcache                                                                                                                                                                                                        
  excludes 'ehcache'                                                                                                                                                                                                                       
}  

所以现在ehcache被排除在外。

将这 5 个 jar 从terracotta安装复制到foo/lib目录:

ehcache-core-ee-2.6.2.jar
ehcache-terracotta-ee-2.6.2.jar
slf4j-api-1.6.1.jar
slf4j-jdk14-1.6.1.jar
terracotta-toolkit-1.6-runtime-ee-5.2.0.jar

ehcache.xmlgrails-app/conf/目录中创建:

<ehcache>

  <terracottaConfig url="vm4:9510"/>

   <defaultCache
       maxElementsInMemory="50"
       eternal="false"
       timeToIdleSeconds="20"
       timeToLiveSeconds="20"
       overflowToDisk="false"
       diskPersistent="false"
       memoryStoreEvictionPolicy="LRU">

    <terracotta clustered="true" valueMode="serialization"/>
  </defaultCache>

</ehcache>

运行项目grails run-app并获得此异常:

Message: Error creating bean with name 'transactionManagerPostProcessor': Initialization of bean failed; nested exception is org.springframework.beans.factory.BeanCreationException: 
Error creating bean with name 'transactionManager': 
Cannot resolve reference to bean 'sessionFactory' while setting bean property 'sessionFactory'; nested exception is org.springframework.beans.factory.BeanCreationException: 
Error creating bean with name 'sessionFactory': Invocation of init method failed; nested exception is org.hibernate.cache.CacheException: 
net.sf.ehcache.CacheException: Could not create ClusteredInstanceFactory due to missing class. Please verify that terracotta-toolkit is in your classpath.
4

1 回答 1

2

从目录中删除所有 jars foo/lib,并在 BuildConfig.groovy 中插入一些依赖项:

    repositories {
        .....
        mavenRepo "http://www.terracotta.org/download/reflector/releases"
    }
    dependencies {
        runtime 'net.sf.ehcache:ehcache-core:2.6.2'
        runtime 'net.sf.ehcache:ehcache-terracotta:2.6.2'
        runtime 'org.terracotta:terracotta-toolkit-1.6-runtime:5.2.0'
    }

这将允许从 repo 和 classpath 设置中自动下载其他必要的 jar。

而且,如果你像我一样设置开源 terracotta 服务器,企业版 foo/lib/ehcache-terracotta-ee-2.6.2.jar 将导致错误:

错误 - 企业客户端无法连接到开源服务器,连接被拒绝。

关键部分:

运行应用程序grails -noreloading run-app而不是grails run-app绕过重新加载代理。然后分布式缓存应用程序应该可以工作。

ps 将应用程序部署到生产环境不需要额外的工作。

于 2013-01-07T16:17:34.180 回答