get handle of object intercepted by @Around annotation

☆樱花仙子☆ 提交于 2020-01-06 14:43:34

问题


getDescription method of Object of class Title was intercepted by an aspect. How do I get access to instance of object itself.

@Around("execution(String com.*.*.*.Title.getDescription(..))")
public String getInternationalizedTitleDescription(ProceedingJoinPoint joinPoint) throws Throwable {
    if (something){
        return joinPoint.proceed(); 
    } else {
        //here I need access to instance to Title
        //Title t = joinPoint.getObject();
        //return SomeOtherObject.getTitleData(t);
    }
}

回答1:


Use ProceedingJoinPoint#getTarget() or ProceedingJoinPoint#getThis() depending on which object you want.

getTarget()

Returns the target object. This will always be the same object as that matched by the target pointcut designator. Unless you specifically need this reflective access, you should use the target pointcut designator to get at this object for better static typing and performance.

getThis()

Returns the currently executing object. This will always be the same object as that matched by the this pointcut designator. Unless you specifically need this reflective access, you should use the this pointcut designator to get at this object for better static typing and performance.

Basically, this is the object that the method was invoked on (a proxy) and target is the proxied object.



来源:https://stackoverflow.com/questions/22923316/get-handle-of-object-intercepted-by-around-annotation

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!