Bonsoir,
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 : 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 <?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 :
la classe main:
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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 sortie :
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 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()); } }
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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








Répondre avec citation


pour tester fallait mettre un petit message dans le get et non pas ailleurs
merci encor une fois

Partager