2012-05-21 3 views
2

Bonjour, J'implémente ehcache basé sur des annotations dans mon application. J'implémente ceci sur la couche de service et j'utilise DetachedCriteria pour les requêtes, mais ehcache ne fonctionne pas. Quelqu'un peut-il avoir une idée à ce sujet? aidez-moi s'il vous plaît ou me suggérer une autre manière de faire ceci. Merci à l'avanceehcache ne fonctionne pas

Dans ehcache.xml

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

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

</ehcache> 

sur la couche de service que je utilise

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

et applicationContext.xml ehcache est mis en correspondance comme

<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

Peut-être que vous pourriez montrer votre code? J'ai fait un peu avec ehcache, mais je ne peux pas le régurgiter comme c'est l'alphabet. Envisagez de cliquer sur ** Modifier ** sur votre question et d'ajouter une partie du code et de la configuration pertinents. Cela nous donnera un peu de contexte et de quoi travailler. Bonne chance! – jmort253

+0

Salut Raman, avez-vous résolu le problème? J'ai le même problème et j'ai un peu mal. Chaque fois que j'appelle un metodh, il ne crée pas d'instance de cache. C'est ma question: http://stackoverflow.com/questions/11194982/spring-annotation-cache-cachedecoratorfactory-not-configured-for-defaultcache –

+0

Que voulez-vous exactement cachez? – Anubhab

Répondre

0

J'espère que vous avez fait le f étapes suivantes.
1. Vous avez besoin d'un fichier de ehcache.xml avec configuration.Sample appropriés peuvent être trouvés
2.In votre springapplicationcontext.xml voir si vous avez ajouté correctement xsd dans la balise haricots.
Exemple de configuration correcte est ci-dessous montrent:

<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> 

maintenant dans votre méthode utiliser le @Cacheable de import com.googlecode.ehcache.annotations.Cacheable;

Ceci est de mon application et cela devrait fonctionner.