On Mon, Aug 15, 2011 at 1:37 PM, Jared Bunting
<[email protected]> wrote:
...
>> it would solve the following issue
>> https://issues.apache.org/jira/browse/SHIRO-318 as we would be able to
>> inject ServletContext.
> I don't believe this is true. When I attempted to define a singleton in
> a ServletModule that injected ServletContext, I got the same deprecation
> warning. I am led to believe that guice-servlets does not intend to
> support any ServletContext injected into a singleton.
I'm not so sure about that. I did a simple test with ServletModule and
I'm not getting the warning:
public class GuiceListener extends GuiceServletContextListener {
@Override
protected Injector getInjector() {
return Guice.createInjector(Stage.DEVELOPMENT, new
TestServletModule());
}
}
public class TestServletModule extends ServletModule {
@Override
protected void configureServlets() {
serve("/test").with(TestServlet.class);
}
}
@Singleton
public class TestSingleton {
private final ServletContext context;
@Inject
public TestSingleton(ServletContext context) {
this.context = context;
}
}
@Singleton
public class TestServlet extends HttpServlet {
private static final long serialVersionUID = 1L;
private final ServletContext context1;
private final Provider<ServletContext> context2;
private final TestSingleton testSingleton;
@Inject
public TestServlet(ServletContext context1, Provider<ServletContext>
context2,
TestSingleton testSingleton) {
this.context1 = context1;
this.context2 = context2;
this.testSingleton = testSingleton;
}
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
PrintWriter w = resp.getWriter();
w.print("context1=");
w.println(context1);
w.print("context2=");
w.println(context2.get());
}
}
--
Filipe Sousa