我试图在异步模式下通过aop记录HttpServletRequest内容。实现中的切入点的方法有HttpServletRequest作为方法参数。我无法在异步模式下访问它,尽管代码在没有@Async注释的情况下工作正常。
@Async
@AfterReturning(pointcut = "execution(* com.web.dto.util.response.impl.ResponseImpl.prepareResponseDTO(..))", returning = "object")
public void logSearchJSON(JoinPoint joinPoint, final Object object) {
try {
List<Object> objects = getActivityParams(joinPoint);
UserActivity userPersonalization = null;
HttpServletRequest httpServletRequest = (HttpServletRequest) objects.get(0);
if (httpServletRequest.getRequestURI().contains(UserActivityConstant.filter))
httpServletRequest.getRequestURI() returns null.
没有@Async注释
,它工作正常答案 0 :(得分:0)
您是否正确宣布了任务执行者?
您可以在Spring上下文中以这种方式执行此操作:
<task:annotation-driven executor="TaskExecutor"/>
<task:executor id="TaskExecutor"
pool-size="2-5"
queue-capacity="50"
keep-alive="120"
rejection-policy="CALLER_RUNS"/>
您也可以在@Configuration类中执行此操作。