mercredi 12 août 2020

How to Method#getAnnotatedParameterTypes() in spring proxied class

I'm using spring-boot 2+ and created some custom annotation;

@Target({ElementType.PARAMETER})
@Retention(RetentionPolicy.RUNTIME)
public @interface MyCustomAnnotation{
}

When doing:

final AnnotatedType[] annotatedTypes = method.getAnnotatedParameterTypes();

//this will get the original class
//final Class<?> clazz = AopProxyUtils.ultimateTargetClass(bean);

Class<?> annotatedMappedClass = null;
for (AnnotatedType annotatedType : annotatedTypes) {
    if (annotatedType.isAnnotationPresent(MyCustomAnnotation.class)) {
        annotatedMappedClass = TypeFactory.rawClass(annotatedType.getType());
    }
}

it works when bean is not a proxy but when I add the @Transactional annotation it becomes a proxy and stops working. What is the Spring Util to find in the target class?





Aucun commentaire:

Enregistrer un commentaire