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 :

Spring AOP : impossible d'intercepter une méthode d'une classe implementant "Controler"


Sujet :

Spring Java

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Candidat au Club
    Profil pro
    Inscrit en
    Avril 2007
    Messages
    3
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Avril 2007
    Messages : 3
    Par défaut Spring AOP : impossible d'intercepter une méthode d'une classe implementant "Controler"
    Bonjour, je travaille avec Spring AOP et je n'arrive pas à intercepter certaines méthodes. J'ai une classe "Container" qui implémente l'interface "Controller" de Spring. J'aimerais intercepter certaines de ses classes mais la seule qui marche est HandleRequest (c'est à dire la seule méthode définie dans l'interface "Controller").
    Voici ma configuration :

    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
     
    <!-- Advisor configuration -->
    <bean id="actionAdvice" class="com.xxx.yyy.server.web.aspects.ActionAdvice">
    		<property name="actionManager" ref="actionManager"/>
    		<property name="userManager" ref="userManager"/>
    	</bean>
     
    	<bean id="actionPointcut" class="org.springframework.aop.support.NameMatchMethodPointcut">
    		<property name="mappedNames" value="handleRequest,processRequest" />
    	</bean>
     
    	<bean id="actionAdvisor" class="org.springframework.aop.support.DefaultPointcutAdvisor">
    		<property name="advice" ref="actionAdvice"/>
    		<property name="pointcut" ref="actionPointcut"/>
    	</bean>
     
    <bean id="container" class="org.springframework.aop.framework.ProxyFactoryBean">
    		<property name="target" ref="containerTarget"/>
    		<property name="proxyTargetClass" value="true"/>
    		<property name="interceptorNames">
    			<list>
    				<value>actionAdvice</value>
    			</list>
    		</property>
    	</bean>
     
    	<bean id="containerTarget" class="com.xxx.yyy.server.container.Container">
    		<property name="blacklistManager" ref="blacklistManager" />
    		<property name="actionManager" ref="actionManager"/>
    		<property name="userManager" ref="userManager"/>
    	</bean>
    Merci de vos réponses

  2. #2
    Membre Expert Avatar de maxf1
    Profil pro
    Inscrit en
    Novembre 2006
    Messages
    1 229
    Détails du profil
    Informations personnelles :
    Âge : 40
    Localisation : France, Moselle (Lorraine)

    Informations forums :
    Inscription : Novembre 2006
    Messages : 1 229
    Par défaut
    Et ton bean userManager, actionManager et blacklistManager

    Ainsi que les codes de ces beans et de Container.

  3. #3
    Candidat au Club
    Profil pro
    Inscrit en
    Avril 2007
    Messages
    3
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Avril 2007
    Messages : 3
    Par défaut
    Ce sont des manager que j'injecte dans ma classe "Container" avec Spring,
    ils font d'ailleurs eux mêmes appel à des DAO

    Les managers :
    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
     
    <bean id="userManagerTarget"
    		class="com.xxx.yyy.server.services.impl.UserManagerImpl">
    		<property name="userDAO">
    			<ref bean="userDAO" />
    		</property>
    		<property name="actionManager">
    			<ref bean="actionManager" />
    		</property>
    	</bean>
     
    	<bean id="userManager"
    		class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean">
    		<property name="transactionManager">
    			<ref bean="transactionManager" />
    		</property>
    		<property name="target">
    			<ref local="userManagerTarget" />
    		</property>
    		<property name="transactionAttributes">
    			<props>
    				<prop key="*">PROPAGATION_REQUIRED,readOnly</prop>
    			</props>
    		</property>
    	</bean>
     
    	<bean id="blacklistManagerTarget"
    		class="com.xxx.yyy.server.blacklist.service.BlacklistManagerImpl">
    		<property name="blacklistDAO">
    			<ref bean="blacklistDAO" />
    		</property>
    		<property name="userManager">
    			<ref bean="userManager" />
    		</property>
    	</bean>
     
    	<bean id="blacklistManager"
    		class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean">
    		<property name="transactionManager">
    			<ref bean="transactionManager" />
    		</property>
    		<property name="target">
    			<ref local="blacklistManagerTarget" />
    		</property>
    		<property name="transactionAttributes">
    			<props>
    				<prop key="add*">PROPAGATION_REQUIRED</prop>
    				<prop key="remove*">PROPAGATION_REQUIRED</prop>
    				<prop key="*">PROPAGATION_REQUIRED,readOnly</prop>
    			</props>
    		</property>
    	</bean>
     
    	<bean id="actionManagerTarget"
    		class="com.xxx.yyy.server.services.impl.ActionManagerImpl">
    		<property name="actionDAO">
    			<ref bean="actionDAO" />
    		</property>
    	</bean>
     
    	<bean id="actionManager"
    		class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean">
    		<property name="transactionManager">
    			<ref bean="transactionManager" />
    		</property>
    		<property name="target">
    			<ref local="actionManagerTarget" />
    		</property>
    		<property name="transactionAttributes">
    			<props>
    				<prop key="create*">PROPAGATION_REQUIRED</prop>
    				<prop key="delete*">PROPAGATION_REQUIRED</prop>
    				<prop key="*">PROPAGATION_REQUIRED,readOnly</prop>
    			</props>
    		</property>
    	</bean>
    Les DAO :
    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
     
    <bean id="sessionFactory"
    		class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
    		<property name="configLocation">
    			<value>classpath:hibernate.cfg.xml</value>
    		</property>
    	</bean>
     
    	<bean id="transactionManager"
    		class="org.springframework.orm.hibernate3.HibernateTransactionManager">
    		<property name="sessionFactory">
    			<ref bean="sessionFactory" />
    		</property>
    	</bean>
     
    	<bean id="blacklistDAO"
    		class="com.xxx.yyy.server.blacklist.dao.BlacklistDAOHibernate">
    		<property name="sessionFactory">
    			<ref bean="sessionFactory" />
    		</property>
    	</bean>
     
    	<bean id="userDAO"
    		class="com.xxx.yyy.server.domain.dao.hibernate.UserDAOHibernate">
    		<property name="sessionFactory">
    			<ref bean="sessionFactory" />
    		</property>
    	</bean>
     
    	<bean id="actionDAO"
    		class="com.xxx.yyy.server.domain.dao.hibernate.ActionDAOHibernate">
    		<property name="sessionFactory">
    			<ref bean="sessionFactory" />
    		</property>
    	</bean>

  4. #4
    Candidat au Club
    Profil pro
    Inscrit en
    Avril 2007
    Messages
    3
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Avril 2007
    Messages : 3
    Par défaut
    En fait j'ai compris ou était le problème. Toutes les méthodes que je veux intercepter sont appelées en interne par la méthode handleRequest de ma classe et Spring AOP ne permet pas d'intercepter les méthodes appelées en interne.
    Apparemment, AspectJ peut le faire, je vais donc m'orienter vers cette solution.

Discussions similaires

  1. Réponses: 0
    Dernier message: 30/09/2009, 18h42
  2. modifier un élément d'une form dans une méthode d'une autre form
    Par baldebaran dans le forum Windows Forms
    Réponses: 9
    Dernier message: 14/08/2009, 13h59
  3. portée d'une variable dans une fonction dans une méthode
    Par laurentg2003 dans le forum Général JavaScript
    Réponses: 4
    Dernier message: 29/06/2009, 19h05
  4. Réponses: 6
    Dernier message: 20/04/2007, 15h24
  5. "ajouter une méthode dans une méthode"
    Par Zorgloub dans le forum Langage
    Réponses: 1
    Dernier message: 09/04/2006, 12h53

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