On Wed, Jan 27, 2010 at 8:39 AM, Helmers <[email protected]> wrote:
> I've seen a couple of posts mentioning the warning "Multiple injectors
> detected" from guice-servlet, but they're either related to Struts2
> integration or incorrectly configured modules. None of the posts
> explain what exactly the message means in a unit test environment (if
> it means anything at all), and if there is a *nice* solution...
>
> The "Multiple injectors detected" warnings are distracting me from
> real warnings and errors, so I was hoping I can get rid of it...
>
>
It's not really a problem in a test unless you have multiple threads running
tests that exercise a servlet module.
> I'm using guice 2.0 and guice-servlet 2.0, and no Struts. I have
> subclassed ServletModule, and that module is loaded whenever I create
> an injector; in particular in my unit tests @Before. Whenever I run
> multiple unit tests at once, GuiceFilter.setPipeline() logs this
> warning:
>
> "Multiple injectors detected. Please install only one ServletModule in
> your web application. While you may have more than one injector, you
> should only configure guice-servlet in one of them. (Hint: look for
> legacy ServetModules or multiple calls to Servlets.configure())."
>
> The following test illustrates the 'problem':
>
> public class GuiceWarningTest {
> private Injector injector;
>
> @Before
> public void setUp() {
>
Here create a guiceFilter with no args and store it in a field.
> System.out.println("setUp()");
> injector = Guice.createInjector(new ServletModule());
> }
>
> @After
> public void tearDown() {
> System.out.println("tearDown()");
> injector = null;
> // Clean up static stuff on the GuiceFilter that Guice
> complains about when creating 2 injectors in 1 JVM
> // new GuiceFilter().destroy();
>
Instead, call destroy() on the guicefilter you saved in setUp().
That should fix it.
Dhanji.
--
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.