Win a copy of Learn Spring Security (video course) this week in the Spring forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Doubt regarding advising final classes in spring..

 
Sumeet H Singh
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Spring generates proxies for AOP in 2 ways:

If the target object:
-implements an interface - it will use java.lang.reflect.Proxy class to generate a new class
-doesn't implement an interface - it uses CGLIB to generate a subclass and includes the necessary changes depending upon the advise


If this is the case, can spring advise final classes that implement an interface? (as there is no need to subclass our class)
 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sumeet K Singh wrote:Spring generates proxies for AOP in 2 ways:

If the target object:
-implements an interface - it will use java.lang.reflect.Proxy class to generate a new class
-doesn't implement an interface - it uses CGLIB to generate a subclass and includes the necessary changes depending upon the advise


If this is the case, can spring advise final classes that implement an interface? (as there is no need to subclass our class)


Yes, it if implements an interface, Spring will create a DynamicProxy of it, the DynamicProxy just holds a reference to the real instance of the class called the target. It does not try to extend it, which you can't do with a final class.

Mark
 
Sumeet H Singh
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Mark !
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic