1. pom 引入aop jar


<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-aop</artifactId>
</dependency>


2. 定义切面 Aspect

 


@Aspect
@Component // 这句不能少
public class TestAspect {
  private Logger logger = Logger.getLogger(getClass());

  @Pointcut("execution(* com.test.server1.controller.ComputerController.test(..))")
  public void testPoint() {}

  @Before(value="testPoint()")
  public void handleBeforeMethod()
  {
  logger.info("handleBeforeMethod before");
  }

  @Around(value = "testPoint()")
  public String handleAroundMethod(ProceedingJoinPoint joinPoint) throws Throwable
  {
  logger.info("handleAroundMethod Around");
  return (String) joinPoint.proceed();
  }

  @After(value = "testPoint()")
  public void handleAfterMethod()
  {
  logger.info("handleAfterMethod After");
  }

}

相关文章:

  • 2021-07-20
  • 2021-07-12
  • 2021-12-22
  • 2021-04-05
  • 2021-03-31
猜你喜欢
  • 2021-07-04
  • 2021-05-04
  • 2021-11-23
  • 2021-12-09
  • 2021-11-23
  • 2021-08-23
相关资源
相似解决方案