【发布时间】:2016-01-15 11:10:45
【问题描述】:
我有一个 Spring MVC Web 应用程序,它连接到外部 Web 服务以进行不同的操作。为了计算 Web 请求的服务响应时间,我使用 aspectj 来记录服务调用。我可以完美记录执行 web 服务方法所花费的时间。
但我也想在 HTML 视图中显示这些响应时间。我找不到让这个时间价值回到视图的方法。非常感谢您的想法。
这是我使用 sl4j 将这些时间记录到 CSV 文件的方法。
@Around("execution(* backend.channel.ServiceWrapper.*(..))")
public Object logAroundServiceCall( ProceedingJoinPoint joinPoint ) throws Throwable
{
StopWatch sw = new StopWatch();
sw.start();
Object returnVal = null;
try
{
returnVal = joinPoint.proceed();
}
catch ( Exception e )
{
LOGGER.error( e.getMessage(), e );
}
finally
{
sw.stop();
SERVICE_TIME_LOGGER.info( "{},{}", joinPoint.getSignature().getName(), sw.getTotalTimeMillis() );
}
return returnVal;
}
【问题讨论】:
标签: java spring-mvc aop aspectj thymeleaf