在调用方法时,知道每个方法的运行时间是很有必要的,使用AOP可以很好的实现:
@Aspect
@Component
@Slf4j
public class ServiceLogAspect {
/**
* 环绕通知,打印超时方法日志
* 3s error
* 2s warn
* <2s info
* @param joinPoint
* @return
* @throws Throwable
*/
@Around("execution(* com.ab.service.impl..*.*(..))")
public Object