I am studying for the Spring Core certification and I have some doubts about how Spring handle proxyes for AOP purpose.
So I know that Spring wrap an object with a proxy to give to it AOP behavior, following this schema:
So it works in this way:
Spring automatically create a proxy for my object.
The method call direct toward my object are intercepted by a method interceptor and a PropertyChangeTrack object check if the method call match with a defined advice (using pointcut).
If an advice match it is executed.
Finnally is performed the called method.
Is it this reasoning correct? My first doubt is related to the interface in the previous schema. Why the proxy and the object have to implement a common interface?
I know that Spring can use 2 differnt types of proxyes that are JDK proxy (I think that is the default for Spring and that are interface based) and CGLIB proxy (not default for Spring and that are subclass based):
So I think that the previous case is related to the standard JDK proxy, is it true?
Now I am studtying the official documentation on this link: http://ift.tt/19aOyKb
that show a simple example about how to chose what kind of proxy use (if I want to use CGLIB proxy) I need to use the **proxyTargetClass=true attribute.
But what are the difference from the JDK proxy and the CGLIB proxy? What are better for what? and what are the limitations of these 2 kinds of proxyes?
Tnx
Aucun commentaire:
Enregistrer un commentaire