当我部署到 Tomcat 时,我得到了一个 NPE(这种情况并非每次都会发生,只有在我重新部署时才会发生)。当 RemoteServiceServlet 尝试 loadSerializationPolicy(..) 时,错误是 NullPointerException。我注意到问题出在 servlet.log 方法调用上,当 loadSerializationPolicy 找不到序列化策略文件时(这似乎是另一个问题?也许不是,序列化只会跳过它,idk),所以它尝试记录它但因 NPE 而失败。
如此处所述:https ://github.com/ArcBees/GWTP/issues/289#issuecomment-21675896问题是 RemoteServiceServlet 找不到记录器?我尝试了建议的解决方案,即在我的项目中创建一个新的 DispatchServiceImpl 来替换标准的 GWTP 服务实现并使用 ServletConfig 对象实现 ServletConfigAware 并覆盖 getServletConfig() 和 setServletConfig(...)。然而,这并没有为我解决问题。当我只使用 Chrome 浏览器 Firefox 和 IE(我已经测试过)时,这不会发生。我假设 Chrome 没有找不到策略文件?或者没有进行不必要的检查?
java.lang.NullPointerException
at javax.servlet.GenericServlet.getServletName(GenericServlet.java:238)
at javax.servlet.GenericServlet.log(GenericServlet.java:190)
at com.google.gwt.user.server.rpc.RemoteServiceServlet.loadSerializationPolicy(RemoteServiceServlet.java:103)
at com.google.gwt.user.server.rpc.RemoteServiceServlet.doGetSerializationPolicy(RemoteServiceServlet.java:293)
at com.google.gwt.user.server.rpc.RemoteServiceServlet.getSerializationPolicy(RemoteServiceServlet.java:157)
at com.google.gwt.user.server.rpc.impl.ServerSerializationStreamReader.prepareToRead(ServerSerializationStreamReader.java:491)
at com.google.gwt.user.server.rpc.RPC.decodeRequest(RPC.java:240)
at com.google.gwt.user.server.rpc.RemoteServiceServlet.processCall(RemoteServiceServlet.java:206)
at com.google.gwt.user.server.rpc.RemoteServiceServlet.processPost(RemoteServiceServlet.java:248)
at com.google.gwt.user.server.rpc.AbstractRemoteServiceServlet.doPost(AbstractRemoteServiceServlet.java:62)
at com.gwtplatform.dispatch.server.spring.DispatchServiceImpl.handleRequest(DispatchServiceImpl.java:68)
at org.springframework.web.context.support.HttpRequestHandlerServlet.service(HttpRequestHandlerServlet.java:68)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:99)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:953)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1023)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:589)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:310)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
现在这个问题不会在开发模式下发生。仅在我重新部署到 Tomcat 的随机场合。如果有人有任何有用的建议或以前遇到过这个问题,我将非常感谢您的帮助!
以下是一些可能有助于识别问题的类:
DispatchServiceImpl.java(替换标准的 GWTP DispatchServiceImpl)
@Component("dispatch")
public class DispatchServiceImpl extends AbstractDispatchServiceImpl implements HttpRequestHandler,
ServletContextAware, ServletConfigAware {
private static final long serialVersionUID = 136176741488585959L;
private ServletContext servletContext;
private ServletConfig servletConfig;
@Autowired(required = false)
protected String securityCookieName;
@Autowired
public DispatchServiceImpl(final Logger logger, final Dispatch dispatch,
RequestProvider requestProvider) {
super(logger, dispatch, requestProvider);
}
@Override
public String getSecurityCookieName() {
return securityCookieName;
}
public void setSecurityCookieName(String securityCookieName) {
this.securityCookieName = securityCookieName;
}
@Override
public void handleRequest(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
doPost(request, response);
}
@Override
public void setServletContext(ServletContext arg0) {
this.servletContext = arg0;
}
@Override
public ServletContext getServletContext() {
return servletContext;
}
@Override
public void setServletConfig(ServletConfig servletConfig) {
this.servletConfig = servletConfig;
}
@Override
public ServletConfig getServletConfig() {
return servletConfig;
}
}
服务器模块.java
/**
* Module which binds the handlers and configurations.
*/
@Configuration
@Import({
DefaultModule.class,
PropertyModule.class,
ConfigLoader.class
})
@ComponentScan({
"nz.co.doltech.ims",
"nz.co.doltech.ims.framework.extensions.platform.dispatch.server.spring"
})
@ImportResource("classpath:META-INF/properties.xml")
@EnableAspectJAutoProxy
@EnableTransactionManagement
public class ServerModule extends HandlerModule {
... snip ...
}