samedi 21 mars 2015

How exactly Spring use JDK proxy?

I have some doubts related the 2 kinds of proxies that I can use with Spring.


enter image description here


So, from what I have understand the JDK proxy type is the default one used from Spring and is based on the interface implementation.


From what I have understand (but I am absolutly not sure about this assertion, correct me if it is wrong) using the JDK proxy both the class of the object "wrapped" by the proxy and the proxy itself have to implement an interface.


What exactly represent this interface? As any interface it contains not implemented methods declaration. What method are?


Studying on the online documentation I found this link: http://ift.tt/19aOyKb


Here it is shown an example of the JDK proxy use for AOP behavior but I have some doubts related the previous interface use.


So, as you can see in this link, there are:




  1. The AppConfig configuration class



    @Configuration
    @EnableAspectJAutoProxy
    public class AppConfig {
    @Bean
    public FooService fooService() {
    return new FooService();
    }

    @Bean
    public MyAspect myAspect() {
    return new MyAspect();
    }
    }



I think that @EnableAspectJAutoProxy enable the use of JDK proxy for adding aspect behavior (is it true?)


In this class are definied 2 beans FooService and MyAspect.



  1. FooService that is a typical POJO component:


public class FooService { // various methods }




  1. MyAspect that is an @Aspect-style aspect:


    @Aspect public class MyAspect { @Before("execution(* FooService+.*(..))") public void advice() { // advise FooService methods as appropriate } }




In the scenario above, @EnableAspectJAutoProxy ensures that MyAspect will be properly processed and that FooService will be proxied mixing in the advice that it contributes.


So my doubts are: if the FooService bean is proxied why it don't explicitly implement any interface as (I think) have to be a JDK proxy? What am I missing?


Tnx


Aucun commentaire:

Enregistrer un commentaire