Time: 2024-05-16 Thursday 11:02:01
Author: Jackasher
Spring Aop切面类
通过注解表示该方法的增强类型,并制定Aop的方法
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
| package org.example.service;
import org.aspectj.lang.ProceedingJoinPoint; import org.aspectj.lang.annotation.*; import org.springframework.core.annotation.Order; import org.springframework.stereotype.Component;
@Component @Aspect @Order(2) public class LogAspect {
@Pointcut("execution (* org.example.service.UserService.*(..))") public void genernalAspect(){
}
@Before("genernalAspect()") public void advice(){ System.out.println("我是一个前置通知"); } @AfterReturning("execution (* org.example.service.UserService.*(..))") public void afterReturningAdvice(){ System.out.println("我是一个后置通知"); } @Around("execution (* org.example.service.UserService.*(..))") public void aroundAdvice(ProceedingJoinPoint proceedingJoinPoint) throws Throwable { System.out.println("前环绕"); proceedingJoinPoint.proceed(); System.out.println("后环绕");
} @After("execution (* org.example.service..*(..))") public void afterAdvice(){ System.out.println("最终通知");
} }
|