Friday, April 5, 2019

Spring AOP

1. Spring AOP ?

  • Aspect: Aspect is a class.which have advices, joinpoints etc.
  • Advice: Advice arec method or action that has been take at particular join point. there are 5 types of advice. 
  • Joinpoint: Joinpoint are any point in our program where we want to implement the advice such as method excecution, exception handling, field access etc. but spring only support method execution join point.
  • Pointcut: pointcut are expression of AOP its matches joinpoints.
  • Target Object: it is an object on which we want implement advice by one or more aspects. it is also know as proxied object because spring AOP use proxy to implement AOP.
  • Interceptor: In Spring AOP, it is an aspect which has ony one advice like before advice or after advice etc. where aspect is a class.  
  • AOP Proxy:
  • Weaving:

Types of AOP advices
  • Before advice
  • After returning advice
  • After throwing advice
  • After advice
  • Around advice
Q- What is the mean by Run-time AOP vs Compile-time AOP?

Q- How to get argument of methods in spring AOP ?
Answer:- We can use ProceedingJoinPoint , Joinpointargs() to get argument of methods in spring AOP

Q- Joinpoint VS ProceedingJoinPoint in AOP using aspectJ ? 
Answer :-  

ProceedingJoinPoint : around is a special advice, so use argument of type ProceedingJoinPoint  with around advices only.

Joinpoint  :- user with other advice

 // ProceedingJoinPoint is used only for around advice because around advise is a special advice
@Around("execution(* com.journaldev.spring.model.Employee.getName())")
 public void getEmployeeAroundAdvice(ProceedingJoinPoint joinPoint) 
   throws Throwable{
   System.out.println("find advice before employee method call...");
   Object[] intObj = joinPoint.getArgs();
   for(int i=0;i<intObj.length;i++){
   System.out.println("find my advice after the method...");

No comments:

Post a Comment