2013-01-07 52 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