我正在尝试使用以下错误消息创建一个简单的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");
}
});
答案 0 :(得分:2)
您忘了扩展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";
}
}