GWT Guice/Gin on the server side problem
Hi guys with my question. A GWT project, as i have read Gin i usable only on the client side than Guice is usable on the server side. Here is my question.
Let first post some example code.
Server side.
public class WebchargeServiceImpl extends RemoteServiceServlet implements WebchargeService
{
@Inject
private Injector injector;
@Inject
private ExecuteOperations executeOperations;
.....
executeOperations.do(); ....
Here is the injected class ExecuteOperations
@Singleton
public class ExecuteOperations
{
.........
}
Also i have servlet module class
public class SampleWebGuiceServletConfig extends GuiceServletContextListener
{
@Override
protected Injector getInjector()
{
return Guice.createInjector(Stage.DEVELOPMENT, new SampleWebModule());
}
} // class
.....
public class SampleWebModule extends ServletModule
{
@Override
开发者_Go百科 protected void configureServlets()
{
bind(WebchargeServiceImpl.class); //is it correct to bind a class like that?
} // class
web.xml
<servlet>
<servlet-name>.......WebchargeService</servlet-name>
<servlet-class>.....WebchargeServiceImpl</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>.........WebchargeService</servlet-name>
<url-pattern>/Webcharge/WebchargeService</url-pattern>
</servlet-mapping>
<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>......SampleWebGuiceServletConfig</listener-class>
</listener>
</web-app>
I'm missing something because i get null every time, this code works ok in servlet/jsp env but here... Advice place.
Thanks.
You have to map your WebchargeServiceImpl
servlet in your SampleWebModule
, not in your web.xml
; otherwise it'll be constructed by your servlet container and not by Guice, so it won't be "injected".
How do your servlets get instantiated? Did you install the Guice Servlet Filter?
精彩评论