0

How to edit the method annotation attributes on runtime in springboot project? I've known there's a way to edit by using reflection like invocationHandler.getClass().getDeclaredField("memberValues"); but in the newer springboot environment it doesn't work, cause the invocationHandler that I got is not the instance of AnnotationInvocationHandler but the instance of SynthesizedMergedAnnotationInvocationHandler. In SynthesizedMergedAnnotationInvocationHandler I can't find the method that let me change the value of the annotation fields on the fly.

I'm trying to reused the way that worked in old version just like:

InvocationHandler invocationHandler = Proxy.getInvocationHandler(rateLimit);
Field field = invocationHandler.getClass().getDeclaredField("memberValues");
field.setAccessible(true);
Map params = (Map)field.get(invocationHandler);
params.put("fields1",xxx);

but there's no fields called memberValues

alea
  • 980
  • 1
  • 13
  • 18
near
  • 1

1 Answers1

0

Never mind, I won't use this method anymore, seems like spring dont want annotation fields value been modified at the runtime. i use spring environment to parse dynamic placeholder to solve the problem.

near
  • 1
  • 2
    Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community May 30 '23 at 10:37