Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/image-processing/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 在SpringMVC中以Servlet异步模式检索servletContext_Java_Spring_Spring Mvc_Servlets - Fatal编程技术网

Java 在SpringMVC中以Servlet异步模式检索servletContext

Java 在SpringMVC中以Servlet异步模式检索servletContext,java,spring,spring-mvc,servlets,Java,Spring,Spring Mvc,Servlets,我刚刚在Spring mvc中切换到使用Servlet Async,例如,我有以下代码: @RequestMapping("/report") public Callable<Void> handleRequest() { return new Callable<Void>() { public Void call() throws Exception { handleRequestIntern(); return null;

我刚刚在Spring mvc中切换到使用Servlet Async,例如,我有以下代码:

@RequestMapping("/report")
public Callable<Void> handleRequest() {
   return new Callable<Void>() {
    public Void call() throws Exception {
        handleRequestIntern();
        return null;
        }
    };
}
@RequestMapping(“/report”)
公共可调用HandlerRequest(){
返回新的可调用(){
public Void call()引发异常{
handleRequestIntern();
返回null;
}
};
}
通常,我有一个过滤器,它将用http请求和响应填充和清空ThreadLocal,该请求和响应在代码中进一步用于检索登录的成员,等等

但是,如何在异步模式下执行此操作?我找不到任何SpringMVC工具可以轻松访问请求和响应


注意:当然我可以传入Http请求和响应,但在代码中,它不是web代码,它将访问一个抽象包装器,该包装器将使用ThreadLocal读取属性,如登录成员。

我实现了CallableProcessingInterceptor,并将其添加到spring配置xml中,如下所示。在运行回调前后调用拦截器

<mvc:annotation-driven>
  <mvc:async-support default-timeout="15000">
    <mvc:callable-interceptors>
    <!-- Required to ensure the http request and responsive are available -->
     <bean class="bla.ServletContextHolderAsyncInterceptor" />
    </mvc:callable-interceptors>
   </mvc:async-support>
</mvc:annotation-driven>

然后,它将填充并清空my ThreadLocal,在执行同步时,该线程也会通过Http过滤器填充

Spring通过一个固定的拦截器来填充它的RequestContextHolder类

它在Spring中也用于Hibernate使用:打开/关闭Hibernate会话,而不是在同步模式下使用OpenEntityManagerViewFilter。 关于这一点的帖子: