Marco Gasparetto Marco Gasparetto - 1 year ago 177
Java Question

Spring and cross context: WebAsyncManager cannot be cast to WebAsyncManager

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 (vFabric TC Server) and Spring Framework 3.2.8.

I have configured the Tomcat conf/context.xml to have: `

<Context crossContext="true">...</Context>`.

In the webapp2 JSP I use `

<c:import context="/webapp1" url="/myurl" />`.

When I call the webapp2 JSP I have this error:

HTTP Status 500 - javax.servlet.ServletException: javax.servlet.jsp.JspException: `java.lang.ClassCastException:` `org.springframework.web.context.request.async.WebAsyncManager cannot be cast to` org.springframework.web.context.request.async.WebAsyncManager`

Has anyone else encountered this?

Answer Source

Seems like Spring is not ready for cross context request processing (at least not without a bit of hacking).

FrameworkServlet always tries to get WebAsyncManager from the request attributes. And the way it is extracted can not work across different contexts (class loaders).

I see two possibilities how to workaround this:

  • Implement your own include JSP tag, which will wrap the original request so that Spring specific attributes are not visible (usually the ones starting with org.springframework) to the second context.
  • Put Spring JARs in a shared class loader path (that would be probably the easier way).