Sunday, 28 April 2013

Spring AOP - Types of Advices



Spring AOP

In order to modularize cross-cutting concerns in aspects Spring AOP framework is used. AOP stands for Aspect oriented programming. For example: - when a method is invoked and we want to perform some extra functionality like logging or transaction management before or after the method execution then we can go with AOP. AOP is nothing but a kind of interceptor to intercept few processes. 

Note:- The functionality that should be used at multiple points of an application are turned as cross-cutting concerns.(like:- Security, Logging and Transaction Management).

Advice and Types of Advices
What is advice?

Ans: - Advice is the piece of code or logic for implementing aspects. This is the kind of action to be taken either before or after the method invoked. This is invoked during program execution by Spring AOP framework. (Note: - Aspects is a feature that we want to apply in the application on Global basis.)

Types of Advice

Spring aspects deals with five categories of advice which is mentioned below:

  • Before- Execute an advice before the method execution.

  • After - Execute an advice after the method execution regardless of its result.

  • After returning advice - Execute an advice after the method execution only if method completed successfully.

  • After throwing advice - Execute an advice after the method execution only if method exits by throwing an exception.

  • Around Advice - Execute an advice around the method execution, by combining all three advices above.

No comments:

Post a Comment