将陶土与grails结合起来



创建空grails项目

grails create-app foo

修改的BuildConfig.groovy,未注释

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

所以现在ehcache被排除。

terracotta安装复制这5个jar到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.

foo/lib目录中删除所有jar文件,并在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和类路径设置中自动下载其他必要的jar文件。

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

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

关键部分:

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

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

相关内容

最新更新