javaEEday12-springAOP-通知顺序

This commit is contained in:
xx
2026-11-07 13:47:24 +08:00
parent 661f3646f8
commit 02aa8be524
5 changed files with 83 additions and 2 deletions
@@ -7,7 +7,7 @@ import org.springframework.stereotype.Component;
@Slf4j
@Component
@Aspect
//@Aspect
public class MyAspect1 {
//相同切入点表达式的抽取(定义切入点)
@@ -0,0 +1,27 @@
package com.inmind.aop;
import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.annotation.After;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;
@Slf4j
@Component
@Aspect
@Order(3)
public class MyAspect3 {
@Before("execution(* com.inmind.service.impl.DeptServiceImpl.*(..))")
public void before(){
log.info("before ...3");
}
@After("execution(* com.inmind.service.impl.DeptServiceImpl.*(..))")
public void after(){
log.info("after ...3");
}
}
@@ -0,0 +1,27 @@
package com.inmind.aop;
import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.annotation.After;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;
@Slf4j
@Component
@Aspect
@Order(2)
public class MyAspect4 {
@Before("execution(* com.inmind.service.impl.DeptServiceImpl.*(..))")
public void before(){
log.info("before ...4");
}
@After("execution(* com.inmind.service.impl.DeptServiceImpl.*(..))")
public void after(){
log.info("after ...4");
}
}
@@ -0,0 +1,27 @@
package com.inmind.aop;
import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.annotation.After;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;
@Slf4j
@Component
@Aspect
@Order(1) //用来控制多个切面类谁先执行的操作
public class MyAspect5 {
@Before("execution(* com.inmind.service.impl.DeptServiceImpl.*(..))")
public void before(){
log.info("before ...5");
}
@After("execution(* com.inmind.service.impl.DeptServiceImpl.*(..))")
public void after(){
log.info("after ...5");
}
}
@@ -7,7 +7,7 @@ import org.aspectj.lang.annotation.Aspect;
import org.springframework.stereotype.Component;
@Component
@Aspect//表示当前是AOP类,面向切面生效的
//@Aspect//表示当前是AOP类,面向切面生效的
@Slf4j
public class TimeAspect {