1

我正在尝试创建一个简单的 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");

            }
        });
4

1 回答 1

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";
    }
}

如何进行 GWT 服务器调用(GWT RPC?)

于 2013-04-03T08:40:44.070 回答