snippetjournal

– notes, snippet codes, and my journal

Spring AOP : simple explanation and simple Example

leave a comment »

  • <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

Written by snippetjournal

September 30, 2014 at 3:10 am

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: