Bonjour,
je suis débutant en spring , comme j'ai une application qui tourne déjà en struts +hibernate donc j'ai commencé par spring AOP dans un premier lieu , et après j'ajouterai spring IOC.
Mais j'ai des choses que j'arrive pas a comprendreexemple)
1)Dans le springContext.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 <?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" xsi:schemaLocation=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd"> <!-- Debut de la configuration AOP --> <aop:config> <aop:pointcut id="servicePointcut" expression="execution(* ew.service.*.*(..))"/> <aop:aspect id="loggingAspect" ref="monLogger"> <aop:before method="logMethodEntry" pointcut-ref="servicePointcut"/> <aop:after-returning method="logMethodExit" returning="result" pointcut-ref="servicePointcut"/> </aop:aspect> </aop:config> <bean id="monLogger" class="ew.aop.MonLogger"/> <!-- Fin de la configuration AOP --> <bean name="monService" class="ew.service.MonService" /> </beans>
MonLogger.java
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 package ew.aop; import org.aspectj.lang.JoinPoint; import org.aspectj.lang.JoinPoint.StaticPart; public class MonLogger { // Cette méthode est appelée à chaque fois (et avant) qu'une méthode du package ew.service est interceptée public void logMethodEntry(JoinPoint joinPoint) { Object[] args = joinPoint.getArgs(); // Nom de la méthode interceptée String name = joinPoint.getSignature().toLongString(); StringBuffer sb = new StringBuffer(name + " called with: ["); // Liste des valeurs des arguments reçus par la méthode for(int i = 0; i < args.length; i++) { Object o = args[i]; sb.append("'"+o+"'"); sb.append((i == args.length - 1) ? "" : ", "); } sb.append("]"); System.out.println(sb); } // Cette méthode est appelée à chaque fois (et après) qu'une méthode du package ew.service est interceptée // Elle reçoit en argument 'result' qui est le retour de la méthode interceptée public void logMethodExit(StaticPart staticPart, Object result) { // Nom de la méthode interceptée String name = staticPart.getSignature().toLongString(); System.out.println(name + " returning: [" + result + "]"); } }
ce que j'arrive pas a comprendre c'est :
public void logMethodEntry(JoinPoint joinPoint) + public void logMethodExit(StaticPart staticPart, Object result) ,d'où elles ramènent leurs arguments
Merci d'avance.
Partager