Spring AOP
Spring
is loosely coupled framework it is developed in modular fashion.
Spring
AOP is one of the modules in spring framework.
Spring
AOP stands for Aspect Oriented Program, which is used to integrate primary/business
logic and secondary/cross cutting logic in an application at runtime and will
execute it.
AOP Terminologies
- Aspect
- Target class
- Joinpoint
- Pointcut
- Advice
- Weaving
- Proxy class
Aspect
The class
which contains secondary logic is called aspect.
Example:
Logging, security, transactions, etc.!
Target class
The
class which contains business/primary logic is called target class.
Joinpoint
Joinpoint
is a specific point in the application such as method execution, exception
handling, etc.!
Spring
AOP supports method level Jointpoint.
Pointcut
Pointcut
is an expression, it uses different expressions that are matched with one or
more Jointpoints.
Spring AOP supports AspectJ Pointcut Designators (Execution, within, this, target, args) for use in pointcut expressions.
Advice
It represents when aspect logic should execute.
Types of
Spring advice's
1) Before
2) After
3) Around
4) After returning
5) After throwing
Weaving
the
process of combining target and aspect is called weaving.
proxy
weaving
will generate one new class by combining target, aspect class that generated
class is called proxy class.
spring
AOP will generate proxy class at runtime.
AOP proxy will be a JDK dynamic proxy or a CGLIB proxy.
AspectJ
Spring
AOP aims to provide a simple AOP implementation across spring IOC to solve most
common problems that programmers face.
It is
not intended as a complete solution of AOP.
There
are some limitations using spring AOP
Limitations are:
Spring AOP is a simple implementation of AOP technology. It can be applied only beans.
Spring AOP will generate proxy class at runtime.
Spring AOP supports method level pointcuts.
Compared to AspectJ, Spring AOP much slower.
Due to these
limitations from spring 2.0 the AspectJ integrate with spring AOP.
Both
AspectJ and spring AOP uses different weavings.
AspectJ
is a complete implementation of the AOP technology in Java. It can be applied
on any Java class.
It
generates proxy class at compile time by using AspectJ compiler.
AspectJ
supports compile-time, post-compile and load-time weaving.
but run
time weaving is not available.
Compile-time weaving
The
weaving process happen at compile time.
AspectJ
compiler takes input as source code of our aspect, and our application finally
it generates woven class file as output.
Post-compile weaving
The
weaving process happen at compile time only, but the difference is weaving
happen on binary files Jar files, existing class files with our aspect file.
Load-time weaving
The
weaving happens when the classes are about to load into JVM.
No comments:
Post a Comment