2012-05-21 44 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;

这是我的应用程序,它应该工作。