tlias管理系统-springAOP的多个切面类作用于同一个方法的执行顺序
This commit is contained in:
@@ -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
|
||||
@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");
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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");
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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");
|
||||
}
|
||||
|
||||
}
|
||||
@@ -7,7 +7,7 @@ import org.aspectj.lang.annotation.Aspect;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component
|
||||
@Aspect
|
||||
//@Aspect
|
||||
@Slf4j
|
||||
public class TimeAspect {
|
||||
|
||||
|
||||
@@ -38,7 +38,7 @@ public class DeptServiceImpl implements DeptService {
|
||||
|
||||
@Override
|
||||
public Dept getById(Integer id) {
|
||||
int i = 1/0;
|
||||
// int i = 1/0;
|
||||
return deptMapper.getById(id);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user