我使用Spring Boot并尝试记录每个请求的响应时间。为了达到这个目的,我试着“围绕方面”。代码:
@Aspect
@Component
public class XYZ {
@Around("execution(* org.springframework.web.servlet.DispatcherServlet.service(..))")
public void doBasicProfiling(ProceedingJoinPoint pjp) throws Throwable {
// start stopwatch
long startTime = System.currentTimeMillis();
System.out.println("Before");
pjp.proceed();
long endTime = System.currentTimeMillis();
// stop stopwatch
System.out.println("Me here");
}
}代码被编译了,但问题是,当我执行任何控制器方法时,什么都没有发生。我的意思是我的SOP应该被打印出来,但是他们没有。我错过了什么?
发布于 2017-05-16 19:50:16
这个怎么样?
@Pointcut("@annotation(org.springframework.web.bind.annotation.RequestMapping)")
public void requestMapping() {}
@Pointcut("within(path.to your.controller.package.*)")
public void myController() {}
@Around("requestMapping() || myController()")
public void logAround(ProceedingJoinPoint joinPoint) throws Throwable {
...............
joinPoint.proceed();
...............
}https://stackoverflow.com/questions/44000449
复制相似问题