Friday, 19 June 2015

How To Acсess Target Object Behind a Spring Proxy?

If you have @Autowired spring bean but for some reason (preferably for unit testing purposes in order to stub something) you want to get target object behind Spring proxy:

((Advised)yourAutowiredBean).getTargetSource().getTarget();

AopUtils.isJdkDynamicProxy(yourAutowiredBean) - can confirm you got proxied object if you have any doubts.

No comments:

Post a Comment