Issue
How to dynamically add a method to a Spring bean? (Cannot edit bean sources statically)
Solution
How to dynamically add a method to a Spring bean?
Bean is an object. You dont need to add anything to an already instantiated Object.
I am guessing, you meant to ask "How to dynamically add a method to a class which I dont have edit access"
Answer is,
- You probably dont need to add anything to that class , you probably can extend it and add your method and instantiate it and use that bean instead of the original bean
If you really have to edit class at runtime
Either look at
a) Reflection (https://www.oracle.com/technical-resources/articles/java/javareflection.html)
Or
b) Bytecode Manipulation (Are there alternatives to cglib?)
Answered By - so-random-dude