Hi,
Get the path when the context initializes in the event listener and
send it up to the ServletModule. You can then use it in other
AbstractModules you are implementing and installing in your
ServletModule.
I hope this helps:
public class MyServletConfig extends GuiceServletContextListener {
private String path;
@Override
public void contextInitialized(ServletContextEvent
servletContextEvent) {
this.path =
servletContextEvent.getServletContext().getRealPath("/");
}
@Override
protected Injector getInjector() {
return Guice.createInjector(new MyServletModule(path));
}
}
~Mihai
On Oct 20, 6:21 pm, Gambo <[email protected]> wrote:
> Hi there,
>
> I want to inject the servletContext within my module to bind the
> realpath param to a named object:
>
> public class ServiceModule extends AbstractModule {
>
> protected void configure() {
>
> bind(String.class).annotatedWith(Names.named("realPath")).toInstance(servletContext.getRealPath("/
> temp"));
>
> }
>
> }
>
> Before I injected the servletcontext into one of my services but Guice
> is throwing now a lot of warnings which say that this is not a good
> idea.
>
> How can I achieve this?
>
> Thanks
--
You received this message because you are subscribed to the Google Groups
"google-guice" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/google-guice?hl=en.