问题
I have a module B, which inherits module A. When I call RPC Services from A inside A, they work ok. But when I call the services from A in B, the RPC invocations always fail. Am I missing something?
Thanks in advance for any help.
回答1:
I've found the answer for my question here: http://blog.cloudglow.com/2010/03/making-gwt-rpc-endpoint-independent-of.html
The default GWT RPC service (Servlet) endpoint is @RemoteServiceRelativePath("some_name"), which resolves to /module_base/some_name at runtime on the client. The issue with this approach is that your RPC endpoint is now tied to GWT Module. While this may be fine for some cases, it was not for our situation. Hence this post.
We ended up creating a RPC services factory class that would create a static instance of the service endpoint and also seed it with the right endpoint; something like this:
public class ServicesFactory
{
public static final RPCServiceAsync RPCService = GWT.create(RPCService.class);
static
{
((ServiceDefTarget) RPCService).setServiceEntryPoint(GWT.getHostPageBaseURL() + RPCService.END_POINT);
}
}
回答2:
There is another way of solving it. Simply adding a new servlet mapping for each new method.
<servlet-mapping>
<servlet-name>serverName</servlet-name>
<url-pattern>/Module1</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>serverName</servlet-name>
<url-pattern>/Module2</url-pattern>
</servlet-mapping>
来源:https://stackoverflow.com/questions/5284190/gwt-calling-rpc-service-inside-another-module