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)

Pointcut


A pointcut is an expression for the selection of joinpoints. It can be a collection of joinpoints used to define an advice that has to be executed. By defining pointcuts you can have control of the objects composing the application, at the points where the advices are applied.

As Spring defines method invocation joinpoints, all the methods that can be invoked on a class will be joinpoints.

These are some examples of pointcuts:

  • Methods starting with a certain prefix (such as, getter and setter)

  • Methods with a particular package (such as org.springaop.domain.*)

  • Methods that return a certain kind of output (such as public MyClass get*(...))

  • Any combination of the previous three examples

Pointcut and its components

A pointcut is the composition of a ClassFilter and a MethodMatcher. A ClassFilter narrows the matching of a pointcut or introduction to a given set of target classes, while a MethodMatcher checks whether the target method is eligible for advice.

public interface Pointcut {
public...