Shiro
  1. Shiro
  2. SHIRO-318

Guice integration causes a warning from guice-servlet

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 1.2.0
    • Fix Version/s: 1.2.0
    • Component/s: None
    • Labels:
      None

      Description

      We see this:

      Aug 5, 2011 12:28:49 PM
      com.google.inject.servlet.InternalServletModule$BackwardsCompatibleServletContextProvider
      get
      WARNING: You are attempting to use a deprecated API (specifically,
      attempting to @Inject ServletContext inside an eagerly created
      singleton. While we allow this for backwards compatibility, be warned
      that this MAY have unexpected behavior if you have more than one
      injector (with ServletModule) running in the same JVM. Please consult
      the Guice documentation at
      http://code.google.com/p/google-guice/wiki/Servlets for more
      information.

        Activity

        Hide
        Les Hazlewood added a comment -

        Closing with the 1.2.0 release.

        Show
        Les Hazlewood added a comment - Closing with the 1.2.0 release.
        Hide
        Les Hazlewood added a comment -

        My apologies for not verifying your group earlier. You should have access now - please let me know if you have any problems!

        Show
        Les Hazlewood added a comment - My apologies for not verifying your group earlier. You should have access now - please let me know if you have any problems!
        Hide
        Jared Bunting added a comment -

        It certainly can, was just waiting for my access to do so.

        Show
        Jared Bunting added a comment - It certainly can, was just waiting for my access to do so.
        Hide
        Les Hazlewood added a comment -

        Jared, can this issue be resolved now? I'm just trying to do some house cleaning in an effort to get 1.2 released.

        Show
        Les Hazlewood added a comment - Jared, can this issue be resolved now? I'm just trying to do some house cleaning in an effort to get 1.2 released.
        Hide
        Jared Bunting added a comment -

        The simple @Inject ServletContext is what binds to the "deprecated api". So, an alternative would be to bind our filters to some sort of "ServletContext" scope so that it's not a singleton, but right now Guice is attempting to inject the ServletContext into our filters before guice-servlet has actually registered the ServletContext - hence the warning.

        Another option is to make our filters non-eager, but that's something that can be overridden easily at Injector-creation time.

        The option that I decided to go with is to bind our own ServletContext at binding-time, and rely on that.

        Show
        Jared Bunting added a comment - The simple @Inject ServletContext is what binds to the "deprecated api". So, an alternative would be to bind our filters to some sort of "ServletContext" scope so that it's not a singleton, but right now Guice is attempting to inject the ServletContext into our filters before guice-servlet has actually registered the ServletContext - hence the warning. Another option is to make our filters non-eager, but that's something that can be overridden easily at Injector-creation time. The option that I decided to go with is to bind our own ServletContext at binding-time, and rely on that.
        Hide
        Filipe Sousa added a comment -

        Is there a need to inject a ServletContext with a @Named annotation. Why not simple @Inject ServletContext?

        Show
        Filipe Sousa added a comment - Is there a need to inject a ServletContext with a @Named annotation. Why not simple @Inject ServletContext?
        Hide
        Jared Bunting added a comment -

        Added BeanTypeListener mappings.

        Show
        Jared Bunting added a comment - Added BeanTypeListener mappings.
        Hide
        Jared Bunting added a comment -

        It looks like the filters (well, anything that implements ServletContextSupport) are asking for a ServletContext at startup time via the BeanTypeListener, which guice-servlet doesn't like. We are already binding a ServletContext in ShiroWebModule (with an @Named annotation), so we just need to make sure that that's the one getting injected by BeanTypeListener. I think I'm going to add a BeanTypeListener "mapping" concept for this purpose. (map type->Key for use in BeanTypeListener - right now it assumes a Key w/o annotation).

        Show
        Jared Bunting added a comment - It looks like the filters (well, anything that implements ServletContextSupport) are asking for a ServletContext at startup time via the BeanTypeListener, which guice-servlet doesn't like. We are already binding a ServletContext in ShiroWebModule (with an @Named annotation), so we just need to make sure that that's the one getting injected by BeanTypeListener. I think I'm going to add a BeanTypeListener "mapping" concept for this purpose. (map type->Key for use in BeanTypeListener - right now it assumes a Key w/o annotation).

          People

          • Assignee:
            Jared Bunting
            Reporter:
            Jared Bunting
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development