lundi 30 septembre 2019

"object is not an instance of declaring class" at calling Method.invoke() with JoinPoint in @Before Spring AOP

I want to call each getter of Argument object of each method of Controller of Spring framework through Spring AOP. But when I call the getter, there is an exception which message is "object is not an instance of declaring class".

What am I wrong ?

Thanks in advance.

@Before("execution(* *(..)) && within(@org.springframework.stereotype.Controller *)")
public void beforeController(JoinPoint joinPoint) {

    MethodSignature methodSignature =  (MethodSignature)joinPoint.getSignature();

    StringBuffer methodFullName = new StringBuffer("");

    Class<?>[] parameters = methodSignature.getParameterTypes();

    for (Class<?> parameter : parameters) {

        methodFullName.append("\t" + parameter.getName() + "\n");

        Method[] methods = parameter.getDeclaredMethods();

        for (Method method : methods) {

            if (method.getName().startsWith("get")) {

                try {

                    Object object = method.invoke(parameter);

                    methodFullName.append("\t\t" + object.toString() + "\n");

                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        }

    }

    System.out.println(methodFullName.toString());
}




Aucun commentaire:

Enregistrer un commentaire