已创建空grails项目
grails create-app foo
修改的BuildConfig.groovy,未注释
inherits("global") {
// uncomment to disable ehcache
excludes 'ehcache'
} 所以现在ehcache被排除在外了。
将这5个jars从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.发布于 2013-01-08 00:17:34
从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和类路径设置中自动下载其他必要的jars。
而且,如果像我一样设置开放源码的terracotta服务器,企业版foo/lib/ehcache-terracotta-ee-2.6.2.jar将导致错误:
错误-企业客户端无法连接到开源服务器,连接被拒绝。
关键部分:
使用grails -noreloading run-app而不是grails run-app运行应用程序以绕过重新加载代理。那么分布式缓存应用程序应该可以工作了。
附注:将应用程序部署到生产环境不需要额外的工作。
https://stackoverflow.com/questions/14191761
复制相似问题