在avice中,如何获取建议方法的参数的“类型参数”

问题描述 投票:1回答:1

使用Spring AOP,我正在编写一个带有周围建议的Aspect,它拦截了使用@MyAnnotation注释的任何方法。假设截获的方法声明如下,

@MyAnnotation
public String someMethod(ArrayList<Integer> arrList) {...}

在建议方法中,我想知道第一个参数,即arrList,具有类型参数ArrayListInteger类型。

我试过这样做跟随this question

@Around("@annotation(MyAnnotation)")
public Object advice(ProceedingJoinPoint pjp) {
    Method method = ((MethodSignature) pjp.getSignature()).getMethod();
    Class<?>[] paramsClass = method.getParameterTypes();
    logger.info(((ParameterizedType) paramsClass[0].getGenericSuperclass()).getActualTypeArguments()[0])
    ...
}

但登出的只是一个qazxsw poi。我该怎么办才能打印qazxsw poi?

java spring reflection spring-aop type-parameter
1个回答
1
投票

试试这个:

E
© www.soinside.com 2019 - 2024. All rights reserved.