博客
关于我
Day125.SpringAOP细节 -Spring
阅读量:330 次
发布时间:2019-03-04

本文共 3246 字,大约阅读时间需要 10 分钟。

AOP??

????????

??????????????????AOP??????????????????????????????

?????????

???????????????????????????????????????????????????

???????????

??????????????

execution([?????] [?????] [????/???] [???]([????]))
  • *?????????????????
  • ..???????????????
  • .??????????

???

execution(* com.atguigu.spring.ArithmeticCalculator.*(..))

??ArithmeticCalculator???????????

?????????

????????????@Pointcut???????????????????

?????????

1?IOC???????????

?Spring??AOP???????????IOC????????????????????????

???

//??Calculator beanCalculator calculator = ioc.getBean(Calculator.class);System.out.println(calculator.getClass()); //??????//??Bean????Calculator calculator1 = ioc.getBean("myMathCalculator");System.out.println(calculator1.getClass()); //??????

2??????????????

???????????????????

  • *????????
  • ..???????????????

???

//??????execution(* com.achang.inter.impl.MyMathCalculator.*(..))

3??????????

????????????????

  • @Before??????
  • @After??????
  • @AfterReturning??????
  • @AfterThrowing??????

4?JoinPoint???????????

JoinPoint????????????????????

???

@After("execution(public int com.achang.inter.impl.MyMathCalculator.*(int,int))")public static void logEnd(JoinPoint joinPoint) {    String methodName = joinPoint.getSignature().getName();    System.out.println("?" + methodName + "?????????");}

5???throwing?returning????

??throwing?returning???????????????????

???

@AfterThrowing(value = "execution(public int com.achang.inter.impl.MyMathCalculator.*(int,int))", throwing = "e")public static void logException(JoinPoint joinPoint, Exception e) {    String methodName = joinPoint.getSignature().getName();    System.out.println("?" + methodName + "?????????????" + e);}@AfterReturning(value = "execution(public int com.achang.inter.impl.MyMathCalculator.*(int,int))", returning = "result")public static void logReturn(JoinPoint joinPoint, Object result) {    String methodName = joinPoint.getSignature().getName();    System.out.println("?" + methodName + "??????????????" + result);}

6?Spring????????

  • ??????????????????????
  • ??????????????????Spring???????

7?????

????????????????????????

???

@Around("OniMyPoint()")public Object myAround(ProceedingJoinPoint pjp) throws Throwable {    Object[] args = pjp.getArgs();    String methodName = pjp.getSignature().getName();        try {        //????        System.out.println("?????????" + methodName + "?????");        //??????        Object proceed = pjp.proceed(args);        //????        System.out.println("?????????" + methodName + "????????????" + proceed + "?");    } catch (Exception e) {        //????        System.out.println("?????????" + methodName + "???????????" + e + "?");        throw new RuntimeException(e);    } finally {        //????        System.out.println("?????????" + methodName + "?????");    }    return proceed;}

8????????

??@Order???????????????????????

???

@Order(1)public class LogUtils {    //...}

??AOP??????????

?????AOP??

  • ??????????IOC???
  • ??@Aspect????????
  • ?????????????????
  • ?????????????AOP???
  • ???XML??????

    ??XML??????????

    • ???????????????????
    • XML????????????????
    • ?????????XML????????????

    转载地址:http://edoq.baihongyu.com/

    你可能感兴趣的文章
    NSSet集合 无序的 不能重复的
    查看>>
    NT AUTHORITY\NETWORK SERVICE 权限问题
    查看>>
    ntko文件存取错误_苹果推送 macOS 10.15.4:iCloud 云盘文件夹共享终于来了
    查看>>
    nullnullHuge Pages
    查看>>
    numpy 用法
    查看>>
    Numpy如何使用np.umprod重写range函数中i的python
    查看>>
    oauth2-shiro 添加 redis 实现版本
    查看>>
    OAuth2.0_JWT令牌-生成令牌和校验令牌_Spring Security OAuth2.0认证授权---springcloud工作笔记148
    查看>>
    OAuth2.0_JWT令牌介绍_Spring Security OAuth2.0认证授权---springcloud工作笔记147
    查看>>
    OAuth2.0_介绍_Spring Security OAuth2.0认证授权---springcloud工作笔记137
    查看>>
    OAuth2.0_完善环境配置_把资源微服务客户端信息_授权码存入到数据库_Spring Security OAuth2.0认证授权---springcloud工作笔记149
    查看>>
    OAuth2.0_授权服务配置_Spring Security OAuth2.0认证授权---springcloud工作笔记140
    查看>>
    OAuth2.0_授权服务配置_令牌服务和令牌端点配置_Spring Security OAuth2.0认证授权---springcloud工作笔记143
    查看>>
    OAuth2.0_授权服务配置_客户端详情配置_Spring Security OAuth2.0认证授权---springcloud工作笔记142
    查看>>
    OAuth2.0_授权服务配置_密码模式及其他模式_Spring Security OAuth2.0认证授权---springcloud工作笔记145
    查看>>
    OAuth2.0_授权服务配置_资源服务测试_Spring Security OAuth2.0认证授权---springcloud工作笔记146
    查看>>
    OAuth2.0_环境介绍_授权服务和资源服务_Spring Security OAuth2.0认证授权---springcloud工作笔记138
    查看>>
    OAuth2.0_环境搭建_Spring Security OAuth2.0认证授权---springcloud工作笔记139
    查看>>
    oauth2.0协议介绍,核心概念和角色,工作流程,概念和用途
    查看>>
    OAuth2授权码模式详细流程(一)——站在OAuth2设计者的角度来理解code
    查看>>