I need to add aspects on runtime in AspectJ. Right now I am using Spring AOP. It is not allowing me to add aspects without restarting the JVM.
The following is my aspect in Spring AOP. Now I need to add extra methods to my aspect during runtime.
package com.pennant.aop;
import org.apache.logging.log4j.LogManager;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.context.annotation.EnableAspectJAutoProxy;
import org.springframework.context.annotation.EnableLoadTimeWeaving;
import org.springframework.stereotype.Component;
@Aspect
public class AOPAspect {
@Pointcut("execution(* com.pennant.aop.Test.*(..)) ")
public static boolean someCallWithIfTest() {
return 3 > 0;
}
@Around("@annotation(com.pennant.aop.AroundAdvice)")
public void logAroundAllMethods(ProceedingJoinPoint joinPoint) throws Throwable {
String methodName = joinPoint.getSignature().getName();
String classname = joinPoint.getTarget().getClass().getSimpleName();
LogManager.getLogger(joinPoint.getTarget().getClass()).debug(Literal.ENTERING,classname+1, methodName);
try {
joinPoint.proceed();
}
finally {}
LogManager.getLogger(joinPoint.getTarget().getClass()).debug(Literal.LEAVING,classname+1, methodName);
}
}