【问题标题】:Java Aspect returned value to be used in the method在方法中使用的 Java Aspect 返回值
【发布时间】:2016-05-17 13:58:02
【问题描述】:

我有一个运行特定逻辑的@After java 方面。我需要它返回一个结果(一个对象),该结果可以在切面切入点截获的方法中使用。是否可以?

【问题讨论】:

    标签: java spring aop aspectj spring-aop


    【解决方案1】:

    您需要的是@Around,它允许您将您想要的任何内容返回给建议的对象:

    @Around("com.xyz.myapp.UserService.createUser()")
    public Object userCreationAdvice(ProceedingJoinPoint pjp) throws Throwable {
        //Do something if needed before method execution
        Object retVal = pjp.proceed();
        //Do something if needed after method execution
        return retVal;
    }
    

    【讨论】:

      猜你喜欢
      • 2015-01-20
      • 2015-05-13
      • 2023-01-07
      • 2021-09-04
      • 2016-12-16
      • 2021-05-10
      • 2012-12-18
      • 2014-09-05
      • 1970-01-01
      相关资源
      最近更新 更多