I'm using spring boot 3.1.0 with org.springframework.boot:spring-boot-starter-aop
I can't make the aroundParseInt aspect to trigger.
I do another aspect test (test1) and this one is triggering.
What I trying to making is to intercept the param of the parseInt and modify it (needed).
import static java.lang.System.currentTimeMillis;
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.stereotype.Component;
@Aspect
public class TransformIntegerAspect {
// THIS test aspect WORKS
@Around("execution(* *(..)) && within(bknd.Siam.Dao.cobros.D_Cobros_Admin)")
public Object test1(ProceedingJoinPoint thisJoinPoint) throws Throwable {
long startTime = currentTimeMillis();
Object result = thisJoinPoint.proceed();
System.out.println(thisJoinPoint + " -> " + (currentTimeMillis() - startTime) + " ms");
LoggerManager.log("ISAAC measureExecutionTime");
return result;
}
//this dont work
@Around("execution(int java.lang.Integer.parseInt(String))")
public Object aroundParseInt(ProceedingJoinPoint joinPoint) throws Throwable {
Object[] args = joinPoint.getArgs();
String param = (String) args[0];
// Modify the parameter before the call to Integer.parseInt
String modifiedParam = modifyParam(param);
args[0] = modifiedParam;
Object result = joinPoint.proceed(args);
return result;
}
private String modifyParam(String param) {
// Your custom logic to modify the parameter
// Return the modified parameter\
return param;
}
The config file also has the @EnableAspectJAutoProxy(proxyTargetClass=true)
and a Bean
@Bean
public TransformIntegerAspect transformParseIntAspect() {
return new TransformIntegerAspect();
}
I have some google code and cant make it works.
Also some people saids is possible and other saids is not.
"If they are made by 3rd party libraries, you can still use binary weaving, creating new versions of the 3rd party class files and creating replacement JARs for them. As an alternative, you can use LTW (load-time weaving) and weave them during class-loading." (Spring AOP with aspectj @annotation).
Im expecting to find if is really possible or not and a alternative way without making a utility method.