For ex: i want to log every behavior in a book class. Is it possilbe to do it with Spring-AOP?
CodePudding user response:
you can try with bellow expression in @Around
, for example :
@Pointcut("execution(* AOPviaAnnotation.Book.*(..))")
public void allMethodOfBook() {};
@Around("allMethodOfBook()")
public void logBookInfo(){
...
}
or try with ||
@Pointcut("execution(* AOPviaAnnotation.Book.add(..))")
public void addMethod() {};
@Pointcut("execution(* AOPviaAnnotation.Book.delete(..))")
public void deleteMethod() {};
@Around("addMethod() || deleteMethod()")
public void logBookInfo(){
...
}
CodePudding user response:
I think setting multiple values in pointcut is impossible. I suggest another approach. How about using custom annotations? you can reference this repository
you can do like below.
- write custom annotation
- write Aspect (logging)
- use annotation where you like to log.