获取被@Around注释拦截的对象的句柄 [英] get handle of object intercepted by @Around annotation

查看:78
本文介绍了获取被@Around注释拦截的对象的句柄的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

getDescription方法.如何访问对象本身的实例.

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

推荐答案

根据需要的对象使用 ProceedingJoinPoint#getTarget() ProceedingJoinPoint#getThis().

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.

基本上, this 是在其上调用该方法的对象(代理),而 target 是代理的对象.

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

这篇关于获取被@Around注释拦截的对象的句柄的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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