1.在pom.xml中添加aop依赖

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

2.配置AOP

@Configuration
@Aspect
public class AopConfig {
    @Around("@within(org.springframework.stereotype.Controller) ")
    public Object simpleAop(final ProceedingJoinPoint pjp)throws Throwable{
        try {
            Object[] args = pjp.getArgs();
            System.out.println("args:"+ Arrays.asList(args));
            Object o = pjp.proceed();
            System.out.println("return :"+o);
            return o;
        }catch (Throwable e){
            throw e;
        }
    }
}

注:@within(org.springframework.stereotype.Controller)指明在@Controller注解下程序运行的时候触发这段AOP代码。

Spring Boot集成AOP简单例子

相关文章:

  • 2022-12-23
  • 2021-04-17
  • 2021-08-01
  • 2022-12-23
  • 2021-09-09
  • 2021-08-07
  • 2021-08-23
  • 2021-06-25
猜你喜欢
  • 2021-10-01
  • 2022-12-23
  • 2021-08-19
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案