IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Spring Java Discussion :

[EHCache] Problème d'intégration


Sujet :

Spring Java

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Membre averti
    Inscrit en
    Septembre 2008
    Messages
    22
    Détails du profil
    Informations forums :
    Inscription : Septembre 2008
    Messages : 22
    Par défaut [EHCache] Problème d'intégration
    Bonjour à tous,

    je n'arrive pas à mettre en place une gestion de cache avec ehcache et spring.

    Mon ehcache.xml
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    <ehcache>
        <diskStore path="java.io.tmpdir"/>
        <defaultCache
            maxElementsInMemory="300"
            eternal="false"
            timeToIdleSeconds="500"
            timeToLiveSeconds="500"
            overflowToDisk="false"/>      
        <cache name="METHOD_CACHE"
                    maxElementsInMemory="300"
                    eternal="true"
                    timeToIdleSeconds="500"
            		timeToLiveSeconds="500"
                    overflowToDisk="false"
                    memoryStoreEvictionPolicy="LFU" />    
    </ehcache>
    Mon Application_context.xml

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    <?xml version="1.0" encoding="UTF-8"?>
    <beans xmlns="http://www.springframework.org/schema/beans"
    	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    	xmlns:aop="http://www.springframework.org/schema/aop"
    	xmlns:tx="http://www.springframework.org/schema/tx"
    	xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
                               http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd
                               http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.0.xsd">
     
     
    	<import resource="applicationContext_service.xml" />
    	<import resource="applicationContext_metier.xml" />
    	<import resource="applicationContext_dao.xml" />
     
    	<bean id="cacheManager"
    		class="org.springframework.cache.ehcache.EhCacheManagerFactoryBean">
    		<property name="configLocation">
    			<value>classpath:ehcache.xml</value>
    		</property>
    	</bean>
     
    	<bean id="methodCache"
    		class="org.springframework.cache.ehcache.EhCacheFactoryBean">
    		<property name="cacheManager">
    			<ref local="cacheManager" />
    		</property>
    		<property name="cacheName">
    			<value>METHOD_CACHE</value>
    		</property>
    	</bean>
     
    	<bean id="methodCacheInterceptor"
    		class="fr.su.out.sai.gestiondroitutilisateur.util.MethodCacheInterceptor">
    		<property name="cache">
    			<ref local="methodCache" />
    		</property>
    	</bean>
     
    	<bean id="methodCachePointCut"
    		class="org.springframework.aop.support.RegexpMethodPointcutAdvisor">
    		<property name="advice">
    			<ref local="methodCacheInterceptor" />
    		</property>
    		<property name="patterns">
    			<list>
    				<value>.*getServiceUsers</value>
    				<value>.*service</value>
    				<value>.*dao.*</value>
    			</list>
    		</property>
    	</bean>
     
    	<bean id="myBean"
    		class="org.springframework.aop.framework.ProxyFactoryBean">
    		<property name="target">
    			<ref bean="usersService"/>
    		</property>
    		<property name="interceptorNames">
    			<list>
    				<value>methodCachePointCut</value>
    			</list>
    		</property>
    	</bean>
    </beans>
    Enfin, la classe MethodCacheInterceptor :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    package fr.su.out.sai.gestiondroitutilisateur.util;
     
    import java.io.Serializable;
     
    import net.sf.ehcache.Cache;
    import net.sf.ehcache.Element;
     
    import org.aopalliance.intercept.MethodInterceptor;
    import org.aopalliance.intercept.MethodInvocation;
    import org.apache.commons.logging.Log;
    import org.apache.commons.logging.LogFactory;
    import org.springframework.beans.factory.InitializingBean;
    import org.springframework.util.Assert;
     
    /**
     */
    public class MethodCacheInterceptor implements MethodInterceptor, InitializingBean {
      private static final Log logger = LogFactory.getLog(MethodCacheInterceptor.class);
     
      private Cache cache;
     
      /**
       * sets cache name to be used
       */
      public void setCache(Cache cache) {
        this.cache = cache;
      }
     
      /**
       * Checks if required attributes are provided.
       */
      public void afterPropertiesSet() throws Exception {
        Assert.notNull(cache, "A cache is required. Use setCache(Cache) to provide one.");
      }
     
      /**
       * main method
       * caches method result if method is configured for caching
       * method results must be serializable
       */
      public Object invoke(MethodInvocation invocation) throws Throwable {
        String targetName  = invocation.getThis().getClass().getName();
        String methodName  = invocation.getMethod().getName();
        Object[] arguments = invocation.getArguments();
        Object result;
     
        logger.debug("looking for method result in cache");
        String cacheKey = getCacheKey(targetName, methodName, arguments);
        Element element = cache.get(cacheKey);
        if (element == null) {
          //call target/sub-interceptor
          logger.debug("calling intercepted method");
          result = invocation.proceed();
     
          //cache method result
          logger.debug("caching result");
          element = new Element(cacheKey, (Serializable) result);
          cache.put(element);
        }
        return element.getValue();
      }
     
      /**
       * creates cache key: targetName.methodName.argument0.argument1...
       */
      private String getCacheKey(String targetName,
                                 String methodName,
                                 Object[] arguments) {
        StringBuffer sb = new StringBuffer();
        sb.append(targetName)
          .append(".").append(methodName);
        if ((arguments != null) && (arguments.length != 0)) {
          for (int i=0; i<arguments.length; i++) {
            sb.append(".")
              .append(arguments[i]);
          }
        }
     
        return sb.toString();
      }
    }
    Le code n'est pas appelé lorsque j'appelle la méthode getServiceUsers par exemple...
    Savez-vous d'où cela peut venir ?

    Merci beaucoup d'avance.

    NB : J'ai suivi les indications suivantes:
    http://opensource.atlassian.com/conf...ng+and+EHCache

  2. #2
    Invité de passage
    Inscrit en
    Février 2009
    Messages
    1
    Détails du profil
    Informations forums :
    Inscription : Février 2009
    Messages : 1
    Par défaut Corrections ?
    Aurais tu trouver la solution à ta question ... J'ai exactement le même problème ?

  3. #3
    Membre averti
    Inscrit en
    Septembre 2008
    Messages
    22
    Détails du profil
    Informations forums :
    Inscription : Septembre 2008
    Messages : 22
    Par défaut
    Désolé, pas trouvé

  4. #4
    Membre averti
    Profil pro
    Inscrit en
    Avril 2009
    Messages
    20
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Avril 2009
    Messages : 20
    Par défaut
    Bonjour,

    J'ai peut-être une piste, mais pas sur que cela fonctionne ... J'ai aussi des problème pour mettre en place ehcache.

    Moi je définit les dépendances dans le fichier persistence.xml des ejb ...

    Je les définit ainsi :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    <?xml version="1.0" encoding="UTF-8"?>
    <persistence version="1.0" xmlns="http://java.sun.com/xml/ns/persistence"
                 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                 xsi:schemaLocation="http://java.sun.com/xml/ns/persistence     http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd">
        <persistence-unit name="jpa-201">
            <provider>org.hibernate.ejb.HibernatePersistence</provider>
            <jta-data-source>srmDataSource</jta-data-source>
            <properties>
                <property name="hibernate.transaction.manager_lookup_class"
                          value="org.apache.openejb.hibernate.TransactionManagerLookup"/>
                <property name="hibernate.hbm2ddl.auto" value="create-drop"/>
                <property name="hibernate.cache.provider_class" value="net.sf.ehcache.hibernate.EhCacheProvider"/>
                <property name="hibernate.cache.use_query_cache" value="true"/>
                <property name="hibernate.cache.use_second_level_cache" value="true"/>
                <property name="hibernate.generate_statistics" value="true"/>
                <!--<property name="hibernate.show_sql" value="true"/>-->
                <!--   <property name="hibernate.hbm2ddl.auto" value="update"/>-->
            </properties>
        </persistence-unit>
     
        <persistence-unit name="jpa-logger">
            <provider>org.hibernate.ejb.HibernatePersistence</provider>
            <jta-data-source>srmLoggerDataSource</jta-data-source>
            <class>com.srmvision.persistence.ejb.logger.Log</class>
            <properties>
                <property name="hibernate.transaction.manager_lookup_class"
                          value="org.apache.openejb.hibernate.TransactionManagerLookup"/>
                <property name="hibernate.archive.autodetection" value="hbm"/>
                <property name="hibernate.hbm2ddl.auto" value="create-drop"/>
                <property name="hibernate.cache.provider_class" value="net.sf.ehcache.hibernate.EhCacheProvider"/>
                <property name="hibernate.cache.use_query_cache" value="true"/>
                <property name="hibernate.cache.use_second_level_cache" value="true"/>
                <property name="hibernate.generate_statistics" value="true"/>
                <!--<property name="hibernate.show_sql" value="true"/>-->
                <!--   <property name="hibernate.hbm2ddl.auto" value="update"/>-->
            </properties>
        </persistence-unit>
    </persistence>
    J'ai aussi besoin d'aide, mais ça vous aidera peut-être ...

Discussions similaires

  1. Problème d'intégration de ehcache dans Spring
    Par anthony22360 dans le forum Persistance des données
    Réponses: 24
    Dernier message: 26/06/2013, 16h56
  2. [ehcache] Problème d'intégration de ehcache dans Spring
    Par anthony22360 dans le forum Spring
    Réponses: 0
    Dernier message: 25/06/2013, 19h55
  3. [XSL/JavaScript]problème d'intégration code JS dans le XSL
    Par Devil666 dans le forum Général JavaScript
    Réponses: 4
    Dernier message: 27/04/2005, 16h36
  4. Problème d'intégration de directX9...
    Par Coderm@n dans le forum DirectX
    Réponses: 4
    Dernier message: 12/03/2005, 23h52
  5. [eclipse][struts][tomcat] Problème d'intégration
    Par Alwin dans le forum Eclipse Java
    Réponses: 1
    Dernier message: 03/07/2004, 21h48

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo