Update object private property with groovy

You can update private field an object with below sample code.

def myBean = spring.getBean("myBean");
def f = myBean.getClass().getDeclaredField("myField");
f.setAccessible(true);
f.set(myBean, "new string value");

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.