Spring反射:从代理方法获取原始方法
考虑使用代理类上的Spring反射:从代理方法获取原始方法,spring,Spring,考虑使用代理类上的MethodmyMethodMyClass。它的名称更改类似于CGLIB$myMethod$,并且原始方法的注释不可用 我需要找到带有注释的方法myMethod,@MyAnnotation: Method method = ... method.getName().contains("$myMethod$")) && method.findAnnotation<MyAnnotation>() != null 方法=。。。 method.getNam
Method
myMethodMyClass
。它的名称更改类似于CGLIB$myMethod$
,并且原始方法的注释不可用
我需要找到带有注释的方法myMethod
,@MyAnnotation
:
Method method = ...
method.getName().contains("$myMethod$")) && method.findAnnotation<MyAnnotation>() != null
方法=。。。
method.getName()包含(“$myMethod$”)和&method.findAnnotation()!=无效的
条件的第一部分工作正常,尽管有点不正常,但是找不到注释。有没有办法从代理的方法访问原始方法?您是否想过在
MyClass
上创建一个包装器/装饰器,它将成为代理,MyClass
实例将是常规(非代理)类
UPD:您也可以尝试
aopproxutils.ultimateTargetClass(…)
或AnnotationUtils.findAnnotation(…)
方法,您可以从代理创建对象。然后得到注释。这可能不是个好主意。但这是另一种方法,这有助于注释,但我仍然无法使用代理方法。