Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the meaning of using proxy ( dynamic proxy) in spring framework?

Tags:

I don't know the meaning of using proxy in spring. what is efficient?

like image 839
Linh Avatar asked Feb 09 '10 09:02

Linh


People also ask

What is the use of proxy in Spring?

The Proxy pattern uses a proxy (surrogate) object “in place of” another object. The objective of a proxy object is to control the creation of and access to the real object it represents.

What are the two types of proxies used in Spring?

Spring used two types of proxy strategy one is JDK dynamic proxy and other one is CGLIB proxy.

When should I use dynamic proxy?

Thus, a dynamic proxy class can be used to create a type-safe proxy object for a list of interfaces without requiring pre-generation of the proxy class, such as with compile-time tools.

What is a dynamic proxy?

Dynamic proxies allow one single class with one single method to service multiple method calls to arbitrary classes with an arbitrary number of methods. A dynamic proxy can be thought of as a kind of Facade, but one that can pretend to be an implementation of any interface.


1 Answers

Proxies are used by AOP. In short:

Normally you have.

Caller --> Real object 

But when, for example, you want automatic transaction management, spring puts a proxy of your real object

Caller --> Proxy --> Real object 

where the proxy starts the transaction.

Here is nice article explaining both the essence of proxies and their efficiency (performance) in spring

like image 194
Bozho Avatar answered Sep 18 '22 19:09

Bozho