上课日志怎么样
public class Log {
private long start;
private long end;
public long getStart() {
return start;
}
public void setStart(long start) {
this.start = start;
}
public long getEnd() {
return end;
}
public void setEnd(long end) {
this.end = end;
}
@Override
public String toString() {
return "Log [start=" + start + ", end=" + end + "]";
}
并通过 api 调用传递此对象的实例。
说 BeanOne.methodOne(Log,..) -> BeanTwo.methodTwo(Log,..) 。BeanTwo.methodTwo() 调用外部api,时间记录在Log实例中。
和如下建议
@Around("execution(* methodOne(..)) && args(log)")
public void testAdviceBeanOne(ProceedingJoinPoint pjp,Log log) {
System.out.println("Before methodOne()");
try {
System.out.println(log);
pjp.proceed();
System.out.println(log);
} catch (Throwable e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
System.out.println("After methodOne()");
}
给出输出
Before methodOne()
Log [start=0, end=0]
Log [start=1572408716134, end=1572408716136]
After methodOne()
可能有一个更优雅的解决方案,仍然是我的两分钱