servlet 的 GWT RPC 服务分配异常
Posted
技术标签:
【中文标题】servlet 的 GWT RPC 服务分配异常【英文标题】:GWT RPC Service Allocate exception for servlet 【发布时间】:2013-04-03 08:02:34 【问题描述】:我正在尝试创建一个简单的 RPC 服务,该服务会出现以下错误消息:
[tomcat:launch] Apr 3, 2013 12:50:38 AM org.apache.catalina.core.ApplicationContext log
[tomcat:launch] INFO: Marking servlet SummaryBuilderServiceImpl as unavailable
[tomcat:launch] Apr 3, 2013 12:50:38 AM org.apache.catalina.core.StandardWrapperValve invoke
[tomcat:launch] SEVERE: Allocate exception for servlet SummaryBuilderServiceImpl
[tomcat:launch] java.lang.ClassCastException: com.test.server.SummaryBuilderServiceImpl cannot be cast to javax.servlet.Servlet
[tomcat:launch] at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1149)
[tomcat:launch] at org.apache.catalina.core.StandardWrapper.allocate(StandardWrapper.java:827)
[tomcat:launch] at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:129)
[tomcat:launch] at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
[tomcat:launch] at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
[tomcat:launch] at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)
[tomcat:launch] at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
[tomcat:launch] at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:293)
[tomcat:launch] at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:861)
[tomcat:launch] at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:606)
[tomcat:launch] at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
[tomcat:launch] at java.lang.Thread.run(Thread.java:662)
[tomcat:launch] Apr 3, 2013 12:53:32 AM org.apache.catalina.core.StandardWrapperValve invoke
[tomcat:launch] INFO: Servlet SummaryBuilderServiceImpl is currently unavailable
我的web.xml
有以下映射
<!-- Summary Builder Service -->
<servlet>
<servlet-name>SummaryBuilderServiceImpl</servlet-name>
<servlet-class>com.test.server.SummaryBuilderServiceImpl</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>SummaryBuilderServiceImpl</servlet-name>
<url-pattern>/test/SummaryBuilder</url-pattern>
</servlet-mapping>
服务文件是
@RemoteServiceRelativePath("SummaryBuilder")
public interface SummaryBuilderService extends RemoteService
String sayHelloWorld();
和异步版本
public interface SummaryBuilderServiceAsync
void sayHelloWorld(AsyncCallback<String> hello);
和实现
public class SummaryBuilderServiceImpl implements SummaryBuilderService
@Override
public String sayHelloWorld()
return "Hello World";
我在入口点调用它
final SummaryBuilderServiceAsync summaryBuilderService = GWT.create(SummaryBuilderService.class);
summaryBuilderService.sayHelloWorld(new AsyncCallback<String>()
@Override
public void onSuccess(String arg0)
Window.alert(arg0);
@Override
public void onFailure(Throwable arg0)
arg0.printStackTrace();
Window.alert("Failed to create servlet");
);
【问题讨论】:
【参考方案1】:您忘记扩展 RemoteServiceServlet
,这会使您的 impl
类成为 servlet。
import com.google.gwt.user.server.rpc.RemoteServiceServlet;
public class SummaryBuilderServiceImpl extendes
RemoteServiceServlet implements SummaryBuilderService
@Override
public String sayHelloWorld()
return "Hello World";
How to make an GWT server call(GWT RPC?)
【讨论】:
哦,原来如此。感谢您发现这一点!以上是关于servlet 的 GWT RPC 服务分配异常的主要内容,如果未能解决你的问题,请参考以下文章
GWT Servlet 错误 com.google.gwt.user.client.rpc .StatusCodeException: Tomcat 服务器上的 404
如何使用 GWT-RPC 以外的方式访问 GWT servlet?