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 等