antoinemeyer/mock-in-bean

Mocks injection doesn't work for AOP proxies

xpinjection opened this issue · 2 comments

When AOP is used Spring wraps the initial class with a JDK dynamic proxy or a CGLIB proxy. So bean found for mocks injection is actually a proxy and reflection-based injection doesn't have any effect. It is quite easy to fix in BeanFieldState.resolveTarget: return AopUtils.isAopProxy(bean) ? AopProxyUtils.getSingletonTarget(bean) : bean;

Let me know if PR is needed.

Thanks for reporting this!
This is fixed by #6.
A new version with that fix has been deployed under boot2-v1.2.
Let me know if you face any more issue!

Thank you for quick reaction and for such useful library! Great job!