当我的服务被访问时,我收到一个 404 Not found 异常...我正在向 GWT Guice webapp 添加一个非常简单的 servlet...我正在为我的 servlet 实现使用 RPC。
**更新(我的更改仍然遇到相同的问题):我意识到我可能需要在 ServletModule 类中进行绑定,所以我添加了这个:
protected void configureServlets() {
bind(BCDWebImpl.class).in(Singleton.class);
serve("/a-bcd/abcd/bcdWebUtil").with(BCDWebImpl.class);
我还在我的代码中添加了一个 Window.alert(GWT.getModuleBaseURL()) ,它输出:
http://xx.xx.xx.xx:8080/a-bcd/abcd/
这是我从萤火虫得到的输出:
Request Headersview source
Accept text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Encoding gzip, deflate
Accept-Language en-US,en;q=0.5
Authorization Basic YWxsVXNlcjpwYXNzd29yZA==
Cache-Control no-cache
Connection keep-alive
Content-Length 148
Content-Type text/x-gwt-rpc; charset=utf-8
Cookie JSESSIONID=97FA0BE47F77E170C18B105C509F980D
Host xx.xx.xx.xx:8080
Pragma no-cache
Referer http://xx.xx.xx.xx:8080/a-bcd/
User-Agent Mozilla/5.0 (Windows NT 6.1; WOW64; rv:23.0) Gecko/20100101 Firefox/23.0
X-GWT-Module-Base http://xx.xx.xx.xx:8080/a-bcd/abcd/
X-GWT-Permutation 35D972F27B5773A4C5ACAFE8EA5C1F36
这是我的 web.xml:
<filter>
<filter-name>guiceFilter</filter-name>
<filter-class>com.google.inject.servlet.GuiceFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>guiceFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<servlet>
<servlet-name>BCDWebImpl</servlet-name>
<servlet-class>com.pz.abcd.server.rest.BCDWebImpl</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>BCDWebImpl</servlet-name>
<url-pattern>/a-bcd/abcd/BCDWeb</url-pattern>
</servlet-mapping>
BCDWeb 类:
@RemoteServiceRelativePath("bcdWeb")
public interface BCDWeb extends RemoteService
{
public String getName ();
}
gwt.xml:
<module rename-to='abcd'>
<servlet class="com.pz.abcd.server.rest.BCDWebImpl" path="/bcdWeb" />
BCDEntryPoint.java:
public void onModuleLoad() {
// This is required for Gwt-Platform proxy's generator
DelayedBindRegistry.bind(ginjector);
ginjector.getPlaceManager().revealCurrentPlace();
setUpEnv();
}
private void setUpEnv(){
BCDWebAsync web = GWT.create(BCDWeb.class);
ServiceDefTarget endpoint = (ServiceDefTarget)web;
endpoint.setServiceEntryPoint(GWT.getModuleBaseURL() + "bcdWeb");
web.getName(new AsyncCallback<String>() {
@Override
public void onFailure(Throwable caught) {
GWT.log(caught.getMessage());
}
@Override
public void onSuccess(final String name) {
// do something here;
}
});
}
同样,这个 webapp 正在使用 guice,但我正在尝试添加一个非常简单的 RPC servlet...任何想法可能是什么问题?
提前致谢。