Bonjour,
Je suis un peu perdu. Suite à réalisation d'exemples sur internet, j'ai constaté que parfois, on passe par une méthode vide où l'on définit le pointcut.
Ci-dessous, on passe par deux déclarations de l'advice sans utiliser @pointcut :
Après, ci-dessous, on passe par une méthode avec déclaration du pointcut et appel de la méthode dans les advices @Before :
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 @Component @Aspect public class TestAppli { private static final Logger LOGGER = LoggerFactory.getLogger(TestAppli.class); @Before("@annotation(Loggable)") public void method1(JoinPoint joinPoint){ LOGGER.info("method 1 est appelée"); } @Before("@annotation(Loggable)") public void method2(JoinPoint joinPoint){ LOGGER.info("method 2 est appelée"); } }
S'il vous plait, quel est l'intérêt de passer par : executeLogging() au sein des advices ?
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 @Component @Aspect public class TestAppli{ private static final Logger LOGGER = LoggerFactory.getLogger(TestAppli.class); @Pointcut("@annotation(Loggable)") public void executeLogging(){ } @Before("executeLogging()") public void method1(JoinPoint joinPoint){ LOGGER.info("method 1 est appelée"); } @Before("executeLogging()") public void method2(JoinPoint joinPoint){ LOGGER.info("method 2 est appelée"); } }
Je vous remercie d'avance pour la prise en considération de cette question.
Cordialement,
Vinz
Partager