0

I'm looking to instrument a Spring bean class(a class annotated with @RestController for example),then making sure that the instrumented version of that class is used to create the application context.

I tried to look at the this thread which tries to load the context with a custom class loader. This looks like a viable approach but having less experience with dealing with class loaders, I'm still not sure how to make this work, do I just create my custom class loader and load my classes which are to be instrumented and then just set Spring's class loader as it's parent, so that it can load rest of the classes which I don't care to instrument?, or should I use Java agents for it?, is there any spring lifecycle annotation I can make use of?

  • There's many ways to resolve this. Depending on what you're planing, you might be able to dynamically subclass your bean and replace it using a BeanPostProcessor. That's about how Spring AOP does it. – Rafael Winterhalter Sep 01 '22 at 07:03
  • Hey @RafaelWinterhalter, thanks for the reply, and I will be going that route you're right, what I really have to do is to redefine the given class to use bytebuddy advice, the one problem I face now is to instantiate the bytebuddy generated class with all the dependencies of the bean I want to replace – Pratik Tiwari Sep 01 '22 at 10:30

0 Answers0