javaEEday12-springAOP-通知类型--1

This commit is contained in:
xx
2026-11-07 11:54:54 +08:00
parent eed4b6d830
commit 0e6163b9e0
2 changed files with 45 additions and 1 deletions
@@ -0,0 +1,44 @@
package com.inmind.aop;
import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.*;
import org.springframework.stereotype.Component;
@Slf4j
@Component
@Aspect
public class MyAspect1 {
//前置通知
@Before("execution(* com.inmind.service.impl.DeptServiceImpl.*(..))")
public void before(){
log.info("before ...");
}
@Around("execution(* com.inmind.service.impl.DeptServiceImpl.*(..))")
public Object around(ProceedingJoinPoint joinPoint) throws Throwable {
log.info("around before ...");
//调用目标对象的原始方法执行
Object result = joinPoint.proceed();
log.info("around after ...");
return result;
}
@After("execution(* com.inmind.service.impl.DeptServiceImpl.*(..))")
public void after(){
log.info("after ...");
}
@AfterReturning("execution(* com.inmind.service.impl.DeptServiceImpl.*(..))")
public void afterReturning(){
log.info("afterReturning ...");
}
@AfterThrowing("execution(* com.inmind.service.impl.DeptServiceImpl.*(..))")
public void afterThrowing(){
log.info("afterThrowing ...");
}
}
@@ -7,7 +7,7 @@ import org.aspectj.lang.annotation.Aspect;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
@Component @Component
@Aspect//表示当前是AOP类,面向切面生效的 //@Aspect//表示当前是AOP类,面向切面生效的
@Slf4j @Slf4j
public class TimeAspect { public class TimeAspect {