Use of proxies in Spring AOP

前端 未结 4 1730
南旧
南旧 2020-11-29 00:09

I am reading a book, which talks about enabling AspectJ support in Spring AOP.

Given below is a paragraph taken from the book:

To ena

4条回答
  •  隐瞒了意图╮
    2020-11-29 00:33

    Spring AOP uses either JDK dynamic proxies or CGLIB to create the proxies for your target objects.

    According to Spring documentation, in case your target implements at least one interface, a JDK dynamic proxy will be used. However if your target object does not implement any interfaces then a CGLIB proxy will be created.

    This is how you can force creation of the CGLIB proxies (set proxy-target-class="true"):

     
        
     
    

    When using AspectJ and its autopoxy support you can also force CGLIB proxies. This is where the is used and also here the "proxy-target-class" must be set to true:

    
    

    Please refer to Proxying mechanisms section of Aspect Oriented Programming with Spring documentation for more details.

提交回复
热议问题