我有一個使用GWT-RPC和Guice設置的相當簡單的GWT應用程序。目前我服務於兩件事情,即GWT-RPC服務和一個接受上傳的applet。它看起來是這樣的:使用Restet與Guice DI&GWT
public class MyGuiceModule extends ServletModule {
@Override
protected void configureServlets() {
serve("/path/to/service").with(MyGWTServiceImpl.class);
serve("/path/to/upload").with(MyUploadServlet.class);
//bunch of bindings follow...
}
}
我希望能夠從同一個應用程序服務的Restlet資源或應用程序的Restlet,在我的吉斯模塊,而不是在web.xml配置。以前我使用Restlet設置了REST支持的GWT應用程序,但它沒有使用DI,所以我有點失落,應該如何工作。
埃塔:這裏是我的web.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE web-app
PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
"http://java.sun.com/dtd/web-app_2_3.dtd">
<web-app>
<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>
<listener>
<listener-class>com.whatever.MyGuiceBootstrap</listener-class>
</listener>
<!-- Default page to serve -->
<welcome-file-list>
<welcome-file>home.html</welcome-file>
</welcome-file-list>
</web-app>
更新
這解決了問題,乾杯!
bind(ServerServlet.class).in(Singleton.class);
Map<String,String> initParams = new HashMap<String,String>();
initParams.put("org.restlet.application", "path.to.your.RestletApplication");
serve("/api/*").with(ServerServlet.class,initParams);
UPDATE2
最後一個解決辦法,我改編自http://hpehl.info/google-appengine-restlet-guice.html,讓我用我的資源和單行內注射在guicemodule綁定去了。
你能否提供你的'web.xml'來解決你的問題。我無法想象你到底想要設置什麼。 –
目前,web.xml只是加載一個guiceContextListener。然後,Guice委託給正確的servlet(如MyServletModule中配置),我將它添加到上面。我想要做的是使用相同的方法在路徑上添加一個rest框架(比如/ api)。我認爲這是可能的,但我寧願儘可能使用restlet。感謝您的期待! – tom