Chapter 8. AspectJ weaving models
This chapter covers
- Classifying weaving models
- Using build-time weaving
- Using load-time weaving
Until now, we’ve focused on writing aspects. But for aspects to have effect, you need to weave them. Weaving, a fundamentally critical mechanism in implementing AOP, composes classes and aspects into an executable system.
The most basic form of weaving is build-time source-code weaving, where the AspectJ compiler compiles source files to produce a woven system. Although this form offers the best experience by providing immediate feedback for source-code errors and by eliminating deployment modifications, using a new compiler can impede AOP adoption. One alternative is build-time byte-code weaving, which lets you delay the introduction of the special compiler until after you compile the code. It also offers a way to weave even when you don’t have access to the source code for classes or aspects. Load-time weaving goes further by eliminating the weaving step from the build process. Instead, it weaves classes as they’re loaded into the VM. Load-time weaving is often the first choice for AspectJ-based tools that want to add new functionality in a minimally invasive fashion. All these choices make adoption of AspectJ easier than ever before.