要在方法中使用的 Java Aspect 返回值 [英] Java Aspect returned value to be used in the method

查看:37
本文介绍了要在方法中使用的 Java Aspect 返回值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have an @After java aspect that runs certain logic. I need it to return a result (an object) that can be used in the methods intercepted by the aspect's pointcut. Is it possible?

推荐答案

你需要的是 @Around 它允许你返回任何你想要的东西给被建议的对象:

What you need is @Around which allows you to return whatever you want to the advised object:

@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;
}

这篇关于要在方法中使用的 Java Aspect 返回值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆