Spring and cross context: WebAsyncManager cannot be cast to WebAsyncManager

前端 未结 4 1214
我在风中等你
我在风中等你 2020-12-18 09:03

I want to use the cross context feature in a Spring application so I can import some webapp1 JSP into a webapp2 JSP. I\'m using Eclipse STS with the included Tomcat 7.0.42 (

4条回答
  •  我在风中等你
    2020-12-18 09:22

    Atlassian seems to have a work-around by using this filter:

    https://docs.atlassian.com/atlassian-confluence/latest/com/atlassian/confluence/internal/web/filter/spring/IgnoreWebAsyncManagerFilter.html

    According to the documentation:

    This filter exists to work around an issue with plugins that use SpringMVC. Spring's OncePerRequestFilter calls WebAsyncUtils.getAsyncManager(ServletRequest) to get a WebAsyncManager to determine if the request is asynchronous. getAsyncManager caches the WebAsyncManager it creates as an attribute on the ServletRequest.

    Since the host application and the plugin framework are using Spring classes from different ClassLoaders, that cached WebAsyncManager causes ClassCastExceptions for plugins which use SpringMVC.

    To avoid those exceptions, this filter detects when Spring attempts to cache its WebAsyncManager and ignores the call, ensuring it's never added to the request. Each call to getAsyncManager(ServletRequest will just create a new one, which is then immediately thrown away. But that means the part of the request that is handled in the host application creates instances from its ClassLoader, and the part that is handled in the plugin framework creates instances from the OSGi ClassLoader.

    Maybe you can try to get the source code, If you do so please reply and send me the class, or you can reproduce the behaviour. Seems to create a new object on each request so it avoids serializing it for cross context.

提交回复
热议问题