I was task to log how long a certain method from a maven dependency would take. This is the Aspect class.
@Aspect
@Component
@Order(1)
public class CloseableHttpClientAsp {
private Long startMs;
private Long endMs;
@Pointcut(value = "execution(* org.apache.http.impl.client.CloseableHttpClient.execute(..))")
void executePointcut() {
}
@Before(value = "executePointcut")
public void doBefore(JoinPoint point) throws Throwable {
startMs = new Date().getTime();
}
@After(value = "executePointcut")
public void doAfter(JoinPoint point) throws Throwable {
endMs = new Date().getTime();
Long ellapseMs = endMs - startMs;
// Other logging happens here
}
}
The class CloseableHttpClient
is from org.apache.httpcomponents:httpclient:4.5.13
. It never enters doBefore
and doAfter
. I tried to replace the expression on the @Pointcut
annotation to a class from my project just to check if it will work, and it does. Does that mean I cannot add Aspect to classes that are not from my own project? Is there anyway to accomplish what I need to?