Précédent   Forum des professionnels en informatique > Java > Général Java > Spring
Spring Forum d'entraide pour le framework Spring. Avant de poster -> FAQ Spring
Partagez cette discussion sur d'autres réseaux sociaux : Viadeo Twitter Google Facebook Digg Delicious MySpace Yahoo
Réponse Proposer ce sujet en actualité
 
Outils de la discussion
Publicité
'
Vieux 06/02/2012, 01h49   #1
Invité de passage
 
Homme
Consultant informatique
Inscription : janvier 2012
Messages : 4
Détails du profil
Informations personnelles :
Sexe : Homme
Localisation : Maroc

Informations professionnelles :
Activité : Consultant informatique
Secteur : High Tech - Éditeur de logiciels

Informations forums :
Inscription : janvier 2012
Messages : 4
Points : 3
Points : 3
Par défaut probléme avec @After advice

Bonsoir,

help help help tout marche très bien sauf que lorsque je veux utiliser @After advice j'ai toujours le même résultat que lorsque j'utilise @Before


le fichier de configuration :
Code :
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
<?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:context="http://www.springframework.org/schema/context"
	xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
		http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.1.xsd
		http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.1.xsd">
 
	<aop:aspectj-autoproxy/>
	<bean name="circle" class="org.touyak.model.Circle">
		<property name="name" value="circle name"/>
	</bean>
	<bean name="loggingAspect" class="org.touyak.aspect.LoggingAspect"/>
 
</beans>

l'aspect :

Code :
1
2
3
4
5
6
7
8
9
10
11
12
13
package org.touyak.aspect;
 
import org.aspectj.lang.annotation.After;
import org.aspectj.lang.annotation.Aspect;
 
@Aspect
public class LoggingAspect {
 
	@After("execution(public String getName())")
	public void LoggingAdvice(){
		System.out.println("Advice run, get methode called");
	}
}
la classe main:
Code :
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
package org.touyak;
 
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.touyak.model.Circle;
 
public class AOPmain {
 
	/**
	 * @param args
	 */
	public static void main(String[] args) {
		ApplicationContext ctx=new ClassPathXmlApplicationContext("spring.xml");
		Circle c=ctx.getBean("circle",Circle.class);
		System.out.println(c.getName());
 
	}
 
}
la sortie :
Code :
1
2
3
4
5
6
7
8
9
 
6 févr. 2012 00:30:31 org.springframework.context.support.AbstractApplicationContext prepareRefresh
INFO: Refreshing org.springframework.context.support.ClassPathXmlApplicationContext@1a05308: startup date [Mon Feb 06 00:30:31 WET 2012]; root of context hierarchy
6 févr. 2012 00:30:31 org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions
INFO: Loading XML bean definitions from class path resource [spring.xml]
6 févr. 2012 00:30:33 org.springframework.beans.factory.support.DefaultListableBeanFactory preInstantiateSingletons
INFO: Pre-instantiating singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@1c9b9ca: defining beans [org.springframework.aop.config.internalAutoProxyCreator,circle,loggingAspect]; root of factory hierarchy
Advice run, get methode called
circle name
randomiz est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 06/02/2012, 08h46   #2
Expert Confirmé
 
Homme
Inscription : septembre 2006
Messages : 2 291
Détails du profil
Informations personnelles :
Sexe : Homme

Informations forums :
Inscription : septembre 2006
Messages : 2 291
Points : 2 738
Points : 2 738
Rien de plus normal…

Hint:
l'aspect est exécuté strictement après l'appel de getName.
JeitEmgie est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 06/02/2012, 16h14   #3
Invité de passage
 
Homme
Consultant informatique
Inscription : janvier 2012
Messages : 4
Détails du profil
Informations personnelles :
Sexe : Homme
Localisation : Maroc

Informations professionnelles :
Activité : Consultant informatique
Secteur : High Tech - Éditeur de logiciels

Informations forums :
Inscription : janvier 2012
Messages : 4
Points : 3
Points : 3
merciiii, comme tu l'a dit rien de plus normal pour tester fallait mettre un petit message dans le get et non pas ailleurs merci encor une fois
randomiz est déconnecté   Envoyer un message privé Réponse avec citation 00
Réponse Proposer ce sujet en actualité Cette discussion est résolue.
Outils de la discussion



Fuseau horaire GMT +2. Il est actuellement 18h08.


 
 
 
 
Partenaires

Hébergement Web