美文网首页
spring boot 之 Aspect

spring boot 之 Aspect

作者: _大叔_ | 来源:发表于2019-10-09 13:33 被阅读0次

Aspect 可以自定义要切入的类甚至再细的方法,粒度最小。

package com.wt.cloud.filter;

import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.*;
import org.springframework.stereotype.Component;

@Aspect
@Component
@Slf4j
public class MyAspect {

//    @Before("execution(* com.wt.cloud.web.HelloWeb.*(..))")
//    public void Before(ProceedingJoinPoint point){
//        log.info("执行前");
//    }
//    @After("execution(* com.wt.cloud.web.HelloWeb.*(..))")
//    public void After(ProceedingJoinPoint point){
//        log.info("执行后");
//    }
//    @AfterThrowing("execution(* com.wt.cloud.web.HelloWeb.*(..))")
//    public void AfterThrowing(JoinPoint point){
//        log.info("执行异常");
//    }

    @Around("execution(* com.wt.cloud.web.HelloWeb.*(..))")
    public Object Around(ProceedingJoinPoint point) throws Throwable {
        log.info("MyAspect 环绕执行");
        log.info("MyAspect 参数 ",point.getArgs());
        Object obj = point.proceed();
        log.info("MyAspect 执行完成结果 ",obj);
        return obj;
    }
}

相关文章

网友评论

      本文标题:spring boot 之 Aspect

      本文链接:https://www.haomeiwen.com/subject/elawpctx.html