0

I can sometimes get the annotation via [object].getClass().isAnnotationPresent([Annotation.class]) but sometimes not. So I turn on the debug mode and find the difference: In the fist picture, b.getClass() return the actual class: stan.beans.HisBean enter image description here But in the second picture, it actually return something different, looks like a modified class by Spring framework so I use the proxied word in the title: class packagepath.Handler$$EnhancerBySpringCGLIB$$da96cafa

enter image description here

Thanks to @Teppic I figure out we can use AopProxyUtils.ultimateTargetClass() to get the non-proxied class

But my question now is :

When will SpringCGLB proxy the class? Is there any configuration I can change? Cause I think both my screenshots use the same configuration. They almost shadow each other.

Important Info Thanks to @M. Deinum The second bean class(proxied one) has Spring Cache @Cacheable annotation on some methods

Stan
  • 602
  • 6
  • 23
  • Does this answer your question? [Find annotation in Spring proxy bean](https://stackoverflow.com/questions/6257092/find-annotation-in-spring-proxy-bean) – teppic Sep 07 '22 at 03:11
  • Ah Yes I will close it – Stan Sep 07 '22 at 03:12
  • @teppic Actually I updated the question now – Stan Sep 07 '22 at 04:12
  • 1
    Without seeing the bean sources and configuration this is impossible to answer. – M. Deinum Sep 07 '22 at 06:20
  • @M.Deinum Actually good point! The only difference between the first and second screenshot is that second one( proxied bean ) has the Spring Cache annotation `@Cacheable`. Actually I think that is possibly the reason. Non-looker does have a clear mind!!! – Stan Sep 07 '22 at 12:16
  • My guess: CGLIG proxies in AOP as well as in Spring Cache framework – Stan Sep 07 '22 at 12:24
  • Again without the code it is impossible to answer. Caching is implemented with AOP. – M. Deinum Sep 07 '22 at 12:28
  • It is private code which can not be shown here. But I can tell the biggest difference is the Cache annotation @M. Denium – Stan Sep 07 '22 at 12:35

0 Answers0