2012-05-21 42 views
2

您好我正在我的應用程序中實現基於註釋的ehcache。我正在服務層上實現這一點,我使用DetachedCriteria進行查詢,但ehcache無法正常工作。任何人都可以對此有所瞭解嗎?請幫我或建議我採取其他方式來做到這一點。預先 感謝ehcache不工作

在ehcache.xml中

<defaultCache eternal="true" maxElementsInMemory="100" overflowToDisk="false" /> 

    <cache name="loadAll" maxElementsInMemory="1000" eternal="true" overflowToDisk="false" /> 

</ehcache> 

上服務層我使用

@Cacheable(cacheName="loadAll") 
    List<ShiftDetail> loadAll(DetachedCriteria detachedCriteria); 

和在applicationContext.xml中ehcache的被映射爲

<ehcache:annotation-driven create-missing-caches="true" cache-manager="cacheManager" /> 

<bean id="cacheManager" class="org.springframework.cache.ehcache.EhCacheManagerFactoryBean" > 
      <property name="configLocation" value="/WEB-INF/ehcache.xml"/> 
    </bean> 
+1

也許你可以顯示你的代碼?我用ehcache做了一點,但是我不能像字母表那樣反芻。考慮點擊你的問題上的**編輯**並添加一些相關的代碼和配置。這將給我們一些背景和一些工作。祝你好運! – jmort253

+0

嗨拉曼,你解決了這個問題嗎?我有你的同樣的問題,我有點痛苦。每次我調用metodh時,都不會創建緩存實例。這是我的問題:http://stackoverflow.com/questions/11194982/spring-annotation-cache-cachedecoratorfactory-not-configured-for-defaultcache –

+0

什麼你想要緩存? – Anubhab

回答

0

我希望你已經完成了f正在執行步驟。
1.你需要一個ehcache.xml中文件適當configuration.Sample可以發現
2.In你springapplicationcontext.xml查看是否在豆類標籤添加正確XSD
樣正確的配置低於顯示:

<beans xmlns="http://www.springframework.org/schema/beans" 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xmlns:cache="http://ehcache-spring-annotations.googlecode.com/svn/schema/ehcache-spring" 
xsi:schemaLocation=" 
    http://www.springframework.org/schema/beans 
    http://www.springframework.org/schema/beans/spring-beans-3.2.xsd 
    http://www.springframework.org/schema/context 
    http://www.springframework.org/schema/context/spring-context-3.2.xsd 
    http://www.springframework.org/schema/tx 
    http://www.springframework.org/schema/tx/spring-tx-3.2.xsd 
    http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.2.xsd 
    http://ehcache-spring-annotations.googlecode.com/svn/schema/ehcache-spring 
    http://ehcache-spring-annotations.googlecode.com/svn/schema/ehcache-spring/ehcache-spring-1.2.xsd 
    "> 
<cache:annotation-driven /> 
    <bean id="cacheManager" 
     class="org.springframework.cache.ehcache.EhCacheManagerFactoryBean"> 
     <property name="configLocation" value="/WEB-INF/xml/spring/ehcache.xml" /> 
    </bean> 

</beans> 

現在,在你的方法使用的@Cacheableimport com.googlecode.ehcache.annotations.Cacheable;

這是我的應用程序,它應該工作。