2013-01-07 53 views
3

创建空的Grails项目使用Grails集成兵马俑

grails create-app foo

修改BuildConfig.groovy,取消注释

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

所以现在ehcache被排除在外。

复制这5个罐子从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 

grails-app/conf/目录中创建ehcache.xml

<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. 
+0

您使用的是哪个版本的grails? – allthenutsandbolts

+0

2.1.1其实问题已经解决了。 – Archer

回答

2

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' 
    } 

这将使从回购和CLASSPATH设置其他必要的jar文件自动下载。

而且,如果你设置一个开放源码的兵马俑服务器像我一样,企业版foo的/ lib目录/ ehcache的赤土-EE-2.6.2.jar将导致一个错误:

ERROR - An Enterprise client can not connect to an Opensource Server, Connection refused.

的关键部分:

使用grails -noreloading run-app运行应用程序而不是grails run-app来绕过重装代理。然后分布式缓存应用程序应该工作。

p.s.将应用程序部署到生产中不需要额外的工作。

+1

其实-noreloading做了伎俩。我已经保存在lib的jar(没有运行时maven deps),它的工作原理。谢谢你,兄弟。 – Archer

+0

你们知道这是为什么吗? (它也适用于我。)但是,我希望在我希望自动重新加载的开发环境中启用分布式缓存。错误消息(classpath中缺少jar)让我有希望解决这个问题! – fluxon

+0

也许你可以尝试为此提出一个jira? – coderLMN