[ 
https://issues.apache.org/jira/browse/SHIRO-401?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13542839#comment-13542839
 ] 

Milan Baran commented on SHIRO-401:
-----------------------------------

Actually, the ServletContext is injected from GuiceServletContextListener 
automatically.

It's enough to add these lines into configureShiro method in the ShiroWebModule.
{code}
bindBeanType(TypeLiteral.get(ServletContext.class), 
Key.get(ServletContext.class, Names.named(NAME)));
bind(Key.get(ServletContext.class, Names.named(NAME))).to(ServletContext.class);
{code}

Also, the ServletContext is always available at injector creation time, because 
it's initialized trough GuiceServletContextListener > getInjector.
The only way it is not, is when you initialize ShiroWebModule alone by 
Guice.createInjector, lets say for Unit testing. But there is more problem that 
the ServletContext is not available.
I have done a fake servlet container for guice-shiro unit testing, which work 
quite well. I can share it.
                
> Add the ability to pass Provider<ServletContext> to the constructor of 
> ShiroWebModule
> -------------------------------------------------------------------------------------
>
>                 Key: SHIRO-401
>                 URL: https://issues.apache.org/jira/browse/SHIRO-401
>             Project: Shiro
>          Issue Type: Improvement
>          Components: Integration: Guice
>            Reporter: Jared Bunting
>            Assignee: Jared Bunting
>
> At times, the ServletContext may not be available at injector creation time.  
> In these cases, being able to pass a provider would be useful.

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira

Reply via email to