GuiceServletContextListener.getInjector should have one param: servletContext
- Dominant language
- Java
- Stars
- 12.7k
- Forks
- 1.7k
- Avg merge
- 11m
- Merged PRs (30d)
- 2
Description
_From [gianmarco.gherardi](https://code.google.com/u/gianmarco.gherardi/) on February 16, 2011 11:04:39_
This way, configuration parameters can be passed as constructor parameter to object. For example, this is possible in normal Java application:
public static void main(String[] args) {
String fooServerAddress = args[0];
Injector injector = Guice.createInjector(new FooModule(fooServerAddress));
FooClient client = injector.getInstance(FooClient.class);
...
}
In Servlet application this should became:
public class AppGuiceServletContextListener extends GuiceServletContextListener {
`@`Override
protected Injector getInjector(ServletContext servletContext) {
String fooServerAddress = servletContext.getInitParameter("fooServerAddress");
return Guice.createInjector(new FooModule(fooServerAddress));
}
}
Check also comments on https://code.google.com/p/google-guice/wiki/FrequentlyAskedQuestions and thread on http://groups.google.com/group/google-guice/browse_thread/thread/dad68e87fd94261e
_Original issue: http://code.google.com/p/google-guice/issues/detail?id=603_
Contributor guide
Assessment
This issue has not been assessed yet.