liveBook · Manning

Code weaving

As explained in Spring Start Here, Second Edition

Weaving is the process of combining aspect advice with target program components at selected execution points.

In Spring AOP, weaving attaches an aspect to a target object by wrapping it in a proxy and exposing the proxy instead of the original bean. Calls through the proxy apply the aspect logic, then delegate to the target method. section 6.1

Keep logging out of business logic

When logging lines clutter business code, an aspect can hold that logic separately. Spring’s proxy intercepts calls to selected methods and applies the aspect. section 6.1

Figure 6.3 Weaving an aspect. Instead of giving you a reference to the real bean, Spring gives you a reference to a proxy object, intercepts the method calls, and manages the aspect logic.

Shows Spring returning a proxy reference that intercepts method calls and manages aspect logic. section 6.1

How Spring Start Here, Second Edition covers it

How deep it goes
Defines proxy-based weaving, traces interception and delegation, and defers implementation syntax.
Examples
Uses logging mixed into business code to illustrate separating aspect logic.
What it assumes
Requires the target object to be a Spring-context bean for Spring to intercept its methods.
What you can do after
Understand how a proxy applies aspect logic and delegates a method call to its target.
How it connects
Connects weaving to aspects, advice, pointcuts, target objects, and proxies.

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.