1. package com.wzy.aspect;
    2. import org.aspectj.lang.ProceedingJoinPoint;
    3. import org.aspectj.lang.annotation.*;
    4. import org.springframework.stereotype.Component;
    5. //增强的类
    6. @Component
    7. @Aspect
    8. public class UserProxy {
    9. //抽取公共部分
    10. @Pointcut(value = "execution(* com.wzy.aspect.User.user(..))")
    11. public void pointdemo() {
    12. }
    13. //前置通知
    14. //@Before 注解表示作为前置通知
    15. @Before(value = "pointdemo()")
    16. public void before() {
    17. System.out.println("1、before.........");
    18. }
    19. //后置通知(返回通知)
    20. @AfterReturning(value = "pointdemo()")
    21. public void afterReturning() {
    22. System.out.println("2、afterReturning.........在方法返回值后执行");
    23. }
    24. //最终通知
    25. @After(value = "pointdemo()")
    26. public void after() {
    27. System.out.println("3、after.........在方法后执行");
    28. }
    29. //异常通知
    30. @AfterThrowing(value = "pointdemo()")
    31. public void afterThrowing() {
    32. System.out.println("4、afterThrowing.........");
    33. }
    34. //环绕通知
    35. @Around(value = "pointdemo()")
    36. public void around(ProceedingJoinPoint proceedingJoinPoint) throws Throwable {
    37. System.out.println("环绕之前.........");
    38. //被增强的方法执行
    39. Object proceed = proceedingJoinPoint.proceed();
    40. System.out.println("环绕之后.........");
    41. }
    42. }