- <aop:aspectj-autoproxy />
Many new spring developers forget that Spring AOP is proxy-based, i.e. its main idea is to return aspect-aware bean proxy instead of the bean itself from the context. So, the user thinks that he or she works with the bean itself and calls bean methods. However, the methods are invoked on a proxy object, hence, the proxy may execute aspect logic before/after delegating the call to the target bean.
That’s all is fine but how does proxy-based AOP relate to the ClassCastException? The answer is that spring framework offers two proxying mechanism – JDK proxy-based and CGLIB-based. The first one can create proxies only for the interfaces; the second one is able to proxy concrete classes with particular limitations (feel free to check spring reference to get more about that – 6.6. Proxying mechanisms). The same reference chapter says the following about proxying mechanism selection:
If the target object to be proxied implements at least one interface then a JDK dynamic proxy will be used. All of the interfaces implemented by the target type will be proxied. If the target object does not implement any interfaces then a CGLIB proxy will be created.
reference : Spring AOP top problem #2 – java.lang.ClassCastException: $Proxy7
example basic aop pada spring, contoh nya sederhana dan mudah di pahami, ada contoh konfigurasi dengan annotation dan juga dengan xml