Vikas Gupta: Software architect

Archive for April, 2010

AspectJ PointCut Expressions

Posted by Vikas Gupta on April 15, 2010

The intention of this blog is to explain AspectJ Pointcut Expressions in Spring Applications. In Aspect Oriented Programming, a pointcut is a set of joinpoints. A joinpoint is a point in program execution where you can add additional behavior. Spring applications only support method based joinpoints. So, you can use AspectJ pointcut expressions to define method pointcuts in Spring 2.x applications. Lets discuss some AspectJ pointcut expressions patterns.

Method Signature Patterns

The most typical pointcut expressions are used to match a number of methods by their signatures. A common method based pointcut expression is something like

expression(<method scope> <return type> <fully qualified class name>.*(parametes))
  1. method scope: Advice will be applied to all the methods having this scope. For e.g., public, private, etc. Please note that Spring AOP only supports advising public methods.
  2. return type: Advice will be applied to all the methods having this return type.
  3. fully qualified class name: Advice will be applied to all the methods of this type. If the class and advice are in the same package then package name is not required
  4. parameters: You can also filter the method names based on the types. Two dots(..) means any number and type of parameters.

Read the rest of this entry »


Posted in AspectJ, Spring | Tagged: , | 17 Comments »