Home Tutorial Spring Spring3 Aop Spring AOP tutorials and example codes.

 
 

Share on Google+Share on Google+
Spring AOP tutorials and example codes.
Posted on: August 30, 2010 at 12:00 AM
Advertisement
In this tutorial you will learn about the AOP module of spring framework.

Spring AOP (Aspect Oriented Programming)

What is Spring AOP (Aspect Oriented Programming)?

Spring AOP is a new programming paradigm, which is implemented in pure java and there is no need of special compilation process. It does not need to control the class loader hierarchy, and is thus suitable for use in a Java EE web container or application server.
It is another way of thinking about program structure in terms of aspects or concern. If we compare AOP with OOP (Object oriented Programming), the OOP decomposes the application into hierarchy of objects where as the AOP decomposes the application into Aspect or Concern.  

AOP Concepts

Aspect

An aspect is a subprogram that is associated with a specific property of a program. As that property varies, the effect "ripples" through the entire program. It is functionality or feature that crosscuts over object. AOP also increases modularity of a program.
An aspect is scattered by virtue of function being read over a numbers of unrelated functions. That means changing in one function requires modifying all affected modules. As code making it harder to understand and maintain.

Advice

An advice is an action taken by the aspect at a particular joint point. It is a chunk of code that is executed during program execution. There are various types of advices depending upon the position they are called in a program, such as before, after, around etc.

Types of Advices

1. Before Advice:- The advice which executed before a joinpoint called before advice. The before advice does not have the ability to interrupt the execution flow proceeding at the joint point unless it throws an exception.

2. After return Advice:- The advice which executed after a jointpoint completed normally, called after advice. For example a method returns without throwing an exception.

3. Around Advice:- Around advice is responsible for choosing whether to proceed to the joinpoint or to shortcut executing by returning their own return value or throwing an exception. It performs the custom behavior before and after method invocation by surrounding a joinpoint.

4. After Throwing Advice:- This advice is executed when a method throws an exception.

5. After (finally) Advice:- The advice is executed when program exits the joinpoints normally or by throwing an exception..

Weaving

Weaving is a process of linking aspect with other application or object to create an advice type. This can be accomplished/performed at compile time, run time load time. In spring framework weaving is performed at run time.

Join point

A join point is a point used in Spring AOP framework to represent a method execution. It always point during execution of program or methods or exceptions. It is actually beginning of methods, AOP intercepts at this point to do some other stuff. i.e. beginning of methods doThis(), doExtra(), test(), somethingElse() etc.

Pointcut

In AOP a pointcut is a set of many joinpoints where an advice can execute. When the program execution is reaches to the one of joint point described in pointcut, a chunk of code (known as Advice) associated with that pointcut executed. This provides the extra flexibility to the programmer to merge an additional code, which is executed in already defined point. It is a key concept of AOP, which distinguishes it from older technology offering interception.
Spring supports union, and intersection operation on pointcuts. Union means the method that either pointcut matches. It is more useful pointcut. And Intersection means the method that both pointcuts match. In the above advices around advice is most general type of advice used in AOP.

AOP Proxy

AOP proxy is an object used to implement the aspect contract. This object is created by the AOP framework. In spring framework AOP proxy is JDK dynamic proxy or CGLIB proxy.

Target Object

Those object in spring framework, which is advised by one or more aspects are called target object. These object is always be proxied object because spring AOP is implemented using runtime proxies.

Spring AOP MethodBeforeAdvice
In this tutorial you will learn how use method before advice of spring aop and how to configure it in config.xml file.
 
Spring AOP After Returning advice
In this tutorial you will learn how to invoke a method before Advice using AfterReturningAdvice interface of Spring AOP
 
Spring AOP After Throws Advice
In this tutorial you will learn about Spring After Throws Advice which executed when a method throws an exception
 
Spring AOP Around Advice
In this tutorial you will learn about Spring AOP Around Advice and its mapping in XML file.
 
Spting AOP Static Pointcut
In this example you will learn how use static pointcut of Spring AOP.
 
Spring AOP Dynamic Pointcut
In this example you will learn how use Dynamic pointcut of Spring AOP.
 
Control Flow Pointcut
In this tutorial you will learn about Spring AOP CotrolFlowPointcut.
 
Composable Pointcut - Union
In this tutorial you will learn about Union operation using ComposablePointcut.
 
Composable Pointcut-Intersection
In this tutorial you will learn how to use ComposablePointcut.Intersection to perform Intersection Operation.
 
AspectJ Pointcut Example
In this tutorial you will learn how to use AspectJ pointcut.
 
Pointcut Example Using JdkRegexpMethod
In this tutorial you will learn how to use JdkRegexpMethod in Spring aop pointcut to match the method by name in package.
 
Pointcut NameMethodMatch using BeanFactory
In this example you will learn how to match the method name using BeanFactory.
 
NameMatchMethodPointcut Examples
In this tutorial you will learn how to use NameMatchMethodPointcut class in pointcut to match the methods names.
 
Spring AOP Hello World Example
In this tutorial you will learn how to configure and run spring aop advice.
 
Spring AOP ProxyFactoryBean Example
In this tutorial you will learn how to use Spring AOP ProxyFactory.
 
Spring AOP Profiling Example
In this tutorial you will how to implement Profiling in Spring AOP.
 
Spring AOP AspectJ Logging Example
In this tutorial, you will learn how to use AspectJ in spring for making log in spring application.
 
Spring AOP Pointcut Annotation
In this tutorial you will learn, how to use annotation in poitcut.
 
Spring AOP Advice Ordering
In this tutorial you will learn how to use more than one advices in a single application.
 
Spring AOP concurency Throttle Interceptor
In this tutorial you will see how Interceptor throttles concurrent access.
 
Spring AOP BeanNameAutoProxyCreator
In this tutorial you will learn how to create bean proxy for every bean manually using BeanNameAutoProxyCreator
 
Spring AOP DefaultAdvisorAutoproxyCreator
In this tutorial you will learn how to create proxy bean automatically using DefaultAdvisorAutoproxyCreator
 
Advertisement

Related Tags for Spring AOP tutorials and example codes.:


Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: August 30, 2010

Recommend the tutorial

Advertisements Advertisements
 

 

 

DMCA.com