1. Spring AOP ?
Answer:-
Types of AOP advices
Q- How to get argument of methods in spring AOP ?
Answer:- We can use ProceedingJoinPoint , Joinpoint & args() 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
Answer:-
- 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- How to get argument of methods in spring AOP ?
Answer:- We can use ProceedingJoinPoint , Joinpoint & args() 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...");
System.out.println(joinPoint.getKind());
System.out.println(joinPoint.getTarget());
Object[] intObj = joinPoint.getArgs();
for(int i=0;i<intObj.length;i++){
System.out.println(intObj[i]);
}
joinPoint.proceed();
System.out.println(joinPoint.getSignature().getName());
System.out.println("find my advice after the method...");
}
No comments:
Post a Comment