Are all methods used when using Spring AOP?

When using Spring AOP to create a proxy for a class using NameMatchMethodPointcutcutAdvisor and BeanNameAutoProxyCreator, it essentially makes a proxy for each call to the object, but only applies advice to the consistent methods or somehow creates a Proxied object that has only these methods and uses a regular object to calls to be intercepted?

By the way, I understand that I understand that it proxies every call to the object, but then it only calls the adviser on methods that match, but I can not find a good example / message to confirm this.

+4
source share
2 answers

Depending on the technique used. (It is configured using the proxy-target-class attribute in your aop configuration)

  • Dynamic JDK proxies are proxies by interface - each interface method passes through a proxy server, as you said, and if it matches, this is the "recommended" method, the adviser is used. Otherwise, it is delegated to the original object.

  • CGLIB proxies are actually subclasses defined at runtime of your specific classes. I cannot be sure of this, but I assume that only the "recommended" methods are overridden, the rest retain the definition of the superclass.

However, no matter what mechanism is used:

  • You don’t worry about how proxies are implemented.
  • it doesn’t affect performance in a significant way - Destructive myths: proxy server performance by the Spring proxy performance myths
+6
source

or somehow create a proxied object that only has these methods and uses a regular object for calls that need to be intercepted?

How it works? When a class has a link to a class that is proxied, it has only one link to it. It must either call the proxy class or the non-proxied class. Spring cannot know which methods you are calling, and therefore cannot give you one type if you need to call the recommended method and another type if you have not.

0
source

Source: https://habr.com/ru/post/1301863/


All Articles