创建空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.xml
在grails-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.