title: GWT + Spring: NullPointerException on getServletContext() call
body: <p>I'm currently experimenting with GWT and Spring. More specifically I wanted to make the GreetingService sample to work with Spring on the server side. There are a couple of articles available for realizing this (I'm linking them here since some of you may be interested):</p>
  
  <ul>
  <li><a href="http://ice09.wordpress.com/2009/05/25/google-app-engine-spring-3-and-jpa/" rel="noreferrer">http://ice09.wordpress.com/2009/05/25/google-app-engine-spring-3-and-jpa/</a></li>
  <li><a href="http://code.google.com/p/google-web-toolkit-incubator/wiki/IntegratingWithSpring" rel="noreferrer">http://code.google.com/p/google-web-toolkit-incubator/wiki/IntegratingWithSpring</a></li>
  </ul>
  
  <p>Now I followed the mentioned instructions and when launching everything in the GWT hosted mode, the service on the server-side is also called successfully. But then before the response is being sent back to the client, I get the a NullPointerException when the getServletContext() is being called internally by some Spring framework class. The stacktrace is the following:</p>
  
  <pre><code>WARNING: Nested in org.springframework.web.util.NestedServletException: Request processing failed; nested exception is java.lang.NullPointerException:
  java.lang.NullPointerException
      at javax.servlet.GenericServlet.getServletContext(GenericServlet.java:163)
      at com.google.gwt.user.server.rpc.RemoteServiceServlet.doUnexpectedFailure(RemoteServiceServlet.java:284)
      at com.google.gwt.user.server.rpc.RemoteServiceServlet.doPost(RemoteServiceServlet.java:99)
      at com.jsdev.devbook.server.GWTController.handleRequest(GWTController.java:51)
      at org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapter.handle(SimpleControllerHandlerAdapter.java:48)
      at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:781)
      at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:726)
      at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:636)
      at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:556)
      at javax.servlet.http.HttpServlet.service(HttpServlet.java:713)
      at javax.servlet.http.HttpServlet.service(HttpServlet.java:806)
      at org.mortbay.jetty.servlet.ServletHolder.handle(ServletHolder.java:487)
      at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1093)
      at com.google.apphosting.utils.servlet.TransactionCleanupFilter.doFilter(TransactionCleanupFilter.java:43)
      at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1084)
      at com.google.appengine.tools.development.StaticFileFilter.doFilter(StaticFileFilter.java:121)
      at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1084)
      at org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:360)
      at org.mortbay.jetty.security.SecurityHandler.handle(SecurityHandler.java:216)
      at org.mortbay.jetty.servlet.SessionHandler.handle(SessionHandler.java:181)
      at org.mortbay.jetty.handler.ContextHandler.handle(ContextHandler.java:712)
      at org.mortbay.jetty.webapp.WebAppContext.handle(WebAppContext.java:405)
      at com.google.apphosting.utils.jetty.DevAppEngineWebAppContext.handle(DevAppEngineWebAppContext.java:54)
      at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:139)
      at com.google.appengine.tools.development.JettyContainerService$ApiProxyHandler.handle(JettyContainerService.java:313)
      at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:139)
      at org.mortbay.jetty.Server.handle(Server.java:313)
      at org.mortbay.jetty.HttpConnection.handleRequest(HttpConnection.java:506)
      at org.mortbay.jetty.HttpConnection$RequestHandler.content(HttpConnection.java:844)
      at org.mortbay.jetty.HttpParser.parseNext(HttpParser.java:644)
      at org.mortbay.jetty.HttpParser.parseAvailable(HttpParser.java:211)
      at org.mortbay.jetty.HttpConnection.handle(HttpConnection.java:381)
      at org.mortbay.io.nio.SelectChannelEndPoint.run(SelectChannelEndPoint.java:396)
      at org.mortbay.thread.BoundedThreadPool$PoolThread.run(BoundedThreadPool.java:442)
  </code></pre>
  
  <p>Here's the list of libs I deploy on my server / GWT hosted mode directory:</p>
  
  <pre><code>antlr-3.0.1.jar
  appengine-api-1.0-sdk-1.2.5.jar
  appengine-api-labs-1.2.5.jar
  commons-logging.jar
  datanucleus-appengine-1.0.3.jar
  datanucleus-core-1.1.5.jar
  datanucleus-jpa-1.1.5.jar
  geronimo-jpa_3.0_spec-1.1.1.jar
  geronimo-jta_1.1_spec-1.1.1.jar
  geronimo-servlet_2.5_spec-1.2.jar
  gwt-servlet.jar
  jdo2-api-2.3-eb.jar
  org.springframework.asm-3.0.0.RC1.jar
  org.springframework.beans-3.0.0.RC1.jar
  org.springframework.context-3.0.0.RC1.jar
  org.springframework.context.support-3.0.0.RC1.jar
  org.springframework.core-3.0.0.RC1.jar
  org.springframework.expression-3.0.0.RC1.jar
  org.springframework.orm-3.0.0.RC1.jar
  org.springframework.web-3.0.0.RC1.jar
  org.springframework.web.servlet-3.0.0.RC1.jar
  spring-dao.jar
  </code></pre>
  
  <p>Even more info:<br>
  developing on Mac OSX, Java version 1.6.0_15.</p>
  
  <p>Does someone have a clue what could be the problem here?</p>
  
  <p>Thx a lot.</p>