liveBook · Manning

Proxy

As explained in Spring Start Here, Second Edition

A proxy object intercepts calls to a target object and can apply additional behavior before delegating to it.

In Spring AOP, a proxy stands between callers and a target object. Spring exposes the proxy in place of the target; the proxy applies aspect logic to an intercepted call, then delegates to the target method. This wrapping process is called weaving. section 6.1

The name also appears in a different role: a CommentNotificationProxy is an application component responsible for communicating outside the app, such as sending an email. Interfaces let CommentService depend on that responsibility without depending on its implementation. section 4.1.3

An intercepted method call

When a caller invokes an aspected method through Spring’s proxy, the proxy applies the aspect logic and then calls the target method. Without interception, the call goes directly to the method. section 6.1

Figure 6.4 When a method isn’t aspected, the call goes directly to that method. When we define an aspect for a method, the call goes through the proxy object. The proxy object applies the logic defined by the aspect and then delegates the call to the real method.

Compare the direct call with the proxy-mediated call that applies aspect logic before delegating. section 6.1

How Spring Start Here, Second Edition covers it

How deep it goes
Explains proxy wrapping, interception, aspect execution, and delegation, but stops short of aspect implementation syntax.
Examples
Uses an intercepted Spring method call and an email-sending CommentNotificationProxy.
What it assumes
Requires intercepted targets to be Spring-context beans; names no other prerequisite.
What you can do after
Understand how Spring routes an aspected method call through a proxy before reaching its target.
How it connects
Connects proxies to Spring AOP, aspects, weaving, target objects, and the Spring context.

Also explained in

Compare how 6 books explain proxy →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Spring Start Here, Second Edition. The section links point to the parts of the book it draws on.