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

查看:276
本文介绍了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天全站免登陆