AOP pointcut (using annotation) to log all methods except setters and getters from POJOs when using package by feature directory structure

StackOverflow https://stackoverflow.com/questions/22158401

  •  19-10-2022
  •  | 
  •  

Question

I am using AspectJ (AOP) for logging purpose. I have following package structure:

com.company.base

com.company.base.common.Result.java
(its a POJO containing 3 fields and their setters and getters and implements Serialize)

com.company.base.feature1.User.java
(its a POJO containing 5 fields and their setters and getters and implements Serialize)

com.company.base.feature2.Customer.java
(its a POJO containing 2 fields and their setters and getters and implements Serialize)

my requirement is: 1) log entry and exit messages when any method executes from any class except from POJO's setter and getter 2) minimum line of code should be there

I am using following pointcut definition but its also calling the advise at setters and getters time as well.

@Pointcut("execution(* com.company.base..*(..))")
void allMethodExcution() {}

Please suggest as soon as possible.

Was it helpful?

Solution

I think I got partial answer to my question (may be not the exact one).

1] All the POJOs are annotated with @XmlRootElement so I created one more pointcut and following advise

// join points created by following point cuts
@Pointcut("within(@javax...XmlRootElement *)")
public void beanAnnotatedWithSpecificAnnotation()

@Pointcut("execution(* com.company.base..*(..))")
public void allMethods()

// this is advise
@Before("!beanAnnotatedWithSpecificAnnotation() && allMethods()")
public void applyAdvise(JoinPoint jp) {
// TODO: advise code ...
}

2] But, what if POJO does not contain @XmlRootElement and only implements java.io.Serialize interface?

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top