我目前正在尝试使用GWT和Spring.更具体地说,我想让GreetingService示例在服务器端与Spring一起使用.有几篇文章可以实现这一点(我在这里链接它们,因为你们中的一些人可能会感兴趣):
> http://ice09.wordpress.com/2009/05/25/google-app-engine-spring-3-and-jpa/
> http://code.google.com/p/google-web-toolkit-incubator/wiki/IntegratingWithSpring
现在我按照上面提到的说明进行操作,当在GWT托管模式下启动所有内容时,服务器端的服务也被成功调用.但是在将响应发送回客户端之前,当一些Spring框架类在内部调用getServletContext()时,我得到一个NullPointerException.堆栈跟踪如下:
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)
这是我在服务器/ GWT托管模式目录上部署的lib列表:
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
更多信息:
在Mac OSX上开发,Java版本1.6.0_15.
有人知道这可能是什么问题吗?
多谢.
最佳答案
刚刚发现了这个问题.必须使GWTController实现能够识别Servlet上下文.这可以通过实现ServletContextAware接口并覆盖getServletContext()和setServletContext(..)方法来实现,以便注入上下文.
原文链接:https://www.f2er.com/spring/431406.html我在published a blog post中描述了该问题,并提供了更详细的解决方案.