javaEEday12-springAOP-通知类型--1
This commit is contained in:
@@ -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;
|
||||
|
||||
@Component
|
||||
@Aspect//表示当前是AOP类,面向切面生效的
|
||||
//@Aspect//表示当前是AOP类,面向切面生效的
|
||||
@Slf4j
|
||||
public class TimeAspect {
|
||||
|
||||
|
||||
Reference in New Issue
Block a user