Java – what does it mean to use proxies (dynamic proxies) in the spring framework?

I don't know what it means to use an agent in spring What is efficiency?

Solution

Dynamic proxy is a feature of JDK You can use an invocation handler to implement the interface

Dynamic agents have some overhead For most use cases, overhead is not important The real problem is that dynamic proxies make applications difficult to understand and debug For example, a dynamic proxy will display multiple lines in the stack trace

Dynamic proxies are often used to implement decorators One example is AOP in spring I don't want to go into the details of AOP and won't use AOP terms to keep it simple Some problems are implemented in one class and used in many places Dynamic proxies (and call handlers) simply paste code (provided by spring) to intercept method calls (in fact, dynamic proxy is only the implementation details of this function, and real-time generation of classes is another possibility to implement it.)

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>