SPRING CONCEPTS

Proxies and self-invocation

Spring Concepts / Proxies and self-invocation

A proxy applies configured behaviour before delegating to a target object.

Understand the idea

An external call through an injected proxy can apply advice. A this.method call inside the target bypasses that proxy, so the called method’s advice or transaction annotation is not newly applied. Code can still execute inside a transaction that was already started by the outer proxied call.

A concrete example

caller → proxy → target
target.this.method() → target directly

In the application

See the independently runnable examples in Stage 33, Stage 34.

Use a separate injected collaborator when a distinct advised boundary is required.

See it in a working stage

Related concepts

Read the official documentation ↗
Java 21 · Spring Boot 4.1.1 · Edupoly