tlias管理系统-springAOP的多个切面类作用于同一个方法的执行顺序

This commit is contained in:
2025-10-28 11:50:19 +08:00
parent bdbdfd03ab
commit 396a44ebc7
6 changed files with 84 additions and 3 deletions

View File

@@ -7,7 +7,7 @@ import org.springframework.stereotype.Component;
@Slf4j @Slf4j
@Component @Component
@Aspect //切面类 //@Aspect //切面类
public class MyAspect1 { public class MyAspect1 {
//定义了一个可以通用的切入点表达式 //定义了一个可以通用的切入点表达式

View File

@@ -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
@Order(3)
@Aspect
public class MyAspect2 {
@Before("execution(* com.inmind.service.impl.DeptServiceImpl.*(..))")
public void before(){
log.info("before ...2");
}
@After("execution(* com.inmind.service.impl.DeptServiceImpl.*(..))")
public void after(){
log.info("after ...2");
}
}

View File

@@ -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
@Order(2)
@Aspect
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");
}
}

View File

@@ -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
@Order(1)
@Aspect
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");
}
}

View File

@@ -7,7 +7,7 @@ import org.aspectj.lang.annotation.Aspect;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
@Component @Component
@Aspect //@Aspect
@Slf4j @Slf4j
public class TimeAspect { public class TimeAspect {

View File

@@ -38,7 +38,7 @@ public class DeptServiceImpl implements DeptService {
@Override @Override
public Dept getById(Integer id) { public Dept getById(Integer id) {
int i = 1/0; // int i = 1/0;
return deptMapper.getById(id); return deptMapper.getById(id);
} }