tag:blogger.com,1999:blog-1786615818482917324.post7763629921322688127..comments2023-11-05T01:46:19.476-07:00Comments on Ioannis Canellos Blog: Spring AOP and Reflection PitfallsAnonymoushttp://www.blogger.com/profile/12809065648292689334noreply@blogger.comBlogger6125tag:blogger.com,1999:blog-1786615818482917324.post-59810880165439622872012-11-30T16:14:48.665-08:002012-11-30T16:14:48.665-08:00@Tim: You mention that " Spring bean that is ...@Tim: You mention that " Spring bean that is a proxy does not inherit from the class it wraps". That is the case when you are using dynamic proxies. In the case of cglib proxies, the proxy is a subclass of the proxies class.Anonymoushttps://www.blogger.com/profile/12809065648292689334noreply@blogger.comtag:blogger.com,1999:blog-1786615818482917324.post-60061999694433790862012-11-30T05:12:33.588-08:002012-11-30T05:12:33.588-08:00I wasn't able to get correct behavior from Ref...I wasn't able to get correct behavior from ReflectionUtils when trying to invoke a private method on my proxied Spring bean (I got the same errors I got when I didn't use ReflectionUtils); I think that's because although you say "So if someBean is proxied, it will fail to find the declared field on the proxy, but it will succed using its superclass (SomeBean.class)", that is not the case; a Spring bean that is a proxy does not inherit from the class it wraps (though it will implement all interfaces that the wrapped class implements).<br /><br />However, I was able to get correct behavior by simply reaching into the proxy and pulling out the target (which is of type SomeBean in your example) and invoking the (no-argument) method against it:<br /><br />Method myMethod = SomeBean.class.getDeclaredMethod("myMethod");<br />myMethod.setAccessible(true);<br />Advised advised = (Advised)someBean;<br />SomeBean someBeanTarget = (SomeBean)advised.getTargetSource().getTarget();<br />Object result = myMethod.invoke(someBeanTarget);Timnoreply@blogger.comtag:blogger.com,1999:blog-1786615818482917324.post-49500648435372323902011-03-21T00:45:49.927-07:002011-03-21T00:45:49.927-07:00@Jocehn: In my example the entity manager is not i...@Jocehn: In my example the entity manager is not instantiated in the proxy but it gets injected. I will need more details in order to help you further.Anonymoushttps://www.blogger.com/profile/12809065648292689334noreply@blogger.comtag:blogger.com,1999:blog-1786615818482917324.post-56934444189417923412011-03-21T00:44:43.456-07:002011-03-21T00:44:43.456-07:00@Jochen: In my example the entity manager is not i...@Jochen: In my example the entity manager is not instantiated in the proxy, but it gets injected in it. I would need more details in order to help you further.Anonymoushttps://www.blogger.com/profile/12809065648292689334noreply@blogger.comtag:blogger.com,1999:blog-1786615818482917324.post-76450486758644948462011-03-20T13:19:01.841-07:002011-03-20T13:19:01.841-07:00Thanks. Glad to find the article. I have the feeli...Thanks. Glad to find the article. I have the feeling it's a good start to solve my problem. But I'm not quite there.<br /><br />My case is similar to yours, but the issue is that in my Proxy my EntiyManager does not get instantiated in my proxy. <br /><br />Any ideas? <br /><br />Thanks.<br /><br />JochenJochenhttps://www.blogger.com/profile/00067375515520075427noreply@blogger.comtag:blogger.com,1999:blog-1786615818482917324.post-58270002513173496942010-09-29T10:43:09.108-07:002010-09-29T10:43:09.108-07:00Thanks, this really helped me for using reflection...Thanks, this really helped me for using reflection on Hibernate AnnotationsUnknownhttps://www.blogger.com/profile/15300023171650558891noreply@blogger.com