Book Image

Spring 2.5 Aspect Oriented Programming

Book Image

Spring 2.5 Aspect Oriented Programming

Overview of this book

Developing powerful web applications with clean, manageable code makes the maintenance process much easier. Aspect-Oriented Programming (AOP) is the easiest and quickest way to achieve such results. Spring is the only Java framework to offer AOP features. The combined power of Spring and AOP gives a powerful and flexible platform to develop and maintain feature-rich web applications quickly. This book will help you to write clean, manageable code for your Java applications quickly, utilizing the combined power of Spring and AOP. You will master the concepts of AOP by developing several real-life AOP-based applications with the Spring Framework, implementing the basic components of Spring AOP: Advice, Joinpoint, Pointcut, and Advisor. This book will teach you everything you need to know to use AOP with Spring. It starts by explaining the AOP features of Spring and then moves ahead with configuring Spring AOP and using its core classes, with lot of examples. It moves on to explain the AspectJ support in Spring. Then you will develop a three-layered example web application designed with Domain-Driven Design (DDD) and built with Test-Driven Development methodology using the full potential of AOP for security, concurrency, caching, and transactions.
Table of Contents (13 chapters)

Target sources


Until now, we have used the word "target" to define the object that receives the calls from a caller object, where a proxy was interposed to add logic contained in advices.

In this interposition mechanism, Spring puts at our disposal the interface org.springframework.aop.TargetSource, which returns the object target.

public interface TargetSource {
Class getTargetClass();
boolean isStatic();
Object getTarget() throws Exception;
void releaseTarget(Object target) throws Exception;
}

This interface is interesting as it permits target pooling and hot swapping.

Without specifying the targetSource, the default implementation that wraps the local object is returned and also the target is returned for all the following invocations.

Hot swappable target sources

The target source org.springframework.aop.target.HotSwappableTargetSource allows a proxy's target object to be replaced in a ThreadSafe way with immediate effect, and the caller doesn't lose the reference.

To make the change...