@Async @Aspect @AfterReturnung。我的方法有HttpServletRequest对象作为方法参数,但能够访问它我的aop方法

时间:2016-02-10 20:21:53

标签: java spring servlets asynchronous aspect

我试图在异步模式下通过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注释

,它工作正常

1 个答案:

答案 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类中执行此操作。