Search code examples
javaspringreflectiontestingcglib

How can i get my CGLIB proxied classes working with spring framework's ReflectionUtils?


I have a cglib proxied class because the impl uses both the @Repository @Transactional annotations.

I would like to use spring's reflection utils to set the field value for mocking out one of the fields.

But when reflection utils can not find the field in my class.

How can i get this to work? So then i can mock out the field (collaborator).


Solution

  • CGLIB extends your class and adds the transactional logic in the extended class. Have you tried to use protected fields instead of private?