I want to log time spent to log file when invoke some service methods , now I implement it by AOP
, e.g.
@Around("execution(* sample..TaskService.*(..))")
public Object aroundStat(ProceedingJoinPoint joinPoint) throws Throwable {
long start = System.currentTimeMillis();
Object proceed = joinPoint.proceed();
long end = System.currentTimeMillis();
String methodName = joinPoint.getSignature().getName();
log.info("{} taken time: {} ms",methodName,(end-start));
return proceed;
}
but I want to know how could implement it by using Annotation just like @Trasactional
, e.g.
@Service
@TimeLogging
public class TaskService {
@TimeLogging
List<TaskStatDTO> taskStatusStat(String name){
//...
}
List<TaskStatDTO> finishedTaskStat(String name){
//...
}
//...
}
Could I implement some class and override some method?