I want to use aspect in a method to log something, but I find it cannot trigger if it is an abstract class method.
I have tried both annotation based and execution, also use +
for abstract class. However, all these does not work.
package com.sample.model;
@Data
@Builder
public class ProductBO {
String product;
String value;
}
package com.sample.handler;
public abstract class A {
public abstract void process(Object request) throws Exception;
...
...
protected ProductBO constructBO(String product, String value) {
return RepaymentProductBO
.builder()
.product(product)
.value(value)
.build();
}
...
}
package com.sample.txn.Posthandler;
@Component
public class B extends A {
public abstract void process(Object request) throws Exception {
ProductBO productBO = constructBO("VISA", "VI-123456,
accountNumber);
}
}
package com.sample.aspect;
@Aspect
@Component
public class TransactionAdvice {
@Pointcut("execution(* com.sample.handler.A+.constructBO(..))")
private void logData() {
}
@AfterReturning(pointcut = "logData()", returning = "result")
@SuppressWarnings("unchecked")
public void logData(JoinPoint joinPoint, Object result) {
Object result = joinPoint.proceed();
log("COME IN AfterReturning");
if (result instanceof ProductBO) {
System.out.println("Works...");
}
}
}
Update: If Spring AOP cannot work for this, I am wondering how to resolve it using AspectJ.