SpringAop三、几个概念

PointCut 切点

可以插入增强处理的连接点。


Aspect 切面

是通知和切点的结合。

核心概念Advice

通知器

SpringAOP的核心概念,用户定义的@Around、@Before、@After、@AfterReturning、@AfterThrowing在处理器处理时都会包装成对应的Advice对象,

Advice中持有@Pointcut切入点,以及定义的解析器, 来确定某个方法需要被哪些类Advice处理。

Advice 通知类 – Advisor实例对象

对应关系:

在这里插入图片描述

注:包装拦截器运行时获取chain时,查看org.springframework.aop.framework.adapter.DefaultAdvisorAdapterRegistry#getInterceptors

一个简单的Aspect类

@Aspect
@Component
public class ServiceAspect {

   @Pointcut("execution(public * self.vinylon.spring.service.impl.*.*(..))")
   public void doService() {
   }


   @Before("doService()")
   public void doBefore(){
      System.out.println("before execute service");
   }

   @Around("doService()")
   public Object doAround(ProceedingJoinPoint joinPoint) throws Throwable {
      MethodSignature signature = (MethodSignature) joinPoint.getSignature();
      Method currMethod = signature.getMethod();
      System.out.println("begin execute service : " + currMethod.getDeclaringClass().getName() + currMethod.getName());
      Object result = joinPoint.proceed();

      System.out.println("end execute service : " + currMethod.getDeclaringClass().getName() + currMethod.getName());
      return result;
   }

}

这几个注解留个概念

@Aspect @Pointcut

@Before @Around 等

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值