6

I just started reading about spring , and a book mentioned "Spring AOP is a Proxy based framework" . What is meant by "Proxy based" framework.

6

The framework is using the java.lang.reflect.Proxy to do the work

In general Aspect Oriented Programming (AOP) in Java is implemented by means of instrumenting the target objects in some manner. There are many ways to do this but a common approach is to use the Proxy class.

This provides a facility to create a new object at runtime based on a given interface. You can then adjust the behaviour of the proxy to include extra features, such as logging or security boilerplate code, before handing control over to the original object.

An alternative approach, is to use subclassing. The proxy extends the original class and weaves the aspect before handing back to the super class. This fails if your class has final methods that need proxying.

You can read more about it in the Java reference here: http://download.oracle.com/javase/6/docs/api/java/lang/reflect/Proxy.html

Alternatively, take a look at Spring in Action (pp 124).

2

As Gary Rowe says: some implementations of Aspect Oriented Programming generally rely on the imposition of a layer between the object and the rest of the system. This layer is usually called a proxy or a dynamic proxy.

From the Castle Project site:

Proxy objects can assist in building a flexible application architecture because it allows functionality to be transparently added to code without modifying it. For example, a class could be proxied to add logging or security checking without making the code aware this functionality has been added.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.