JerseyServletModule and resteasy RequestScopeModule - conflicting bindings

89 views
Skip to first unread message

Aseem

unread,
Oct 20, 2014, 3:22:19 PM10/20/14
to google...@googlegroups.com
Hi,

Receiving "A binding to XXX was already configured at YYY" due to using JerseyServletModule and RequestScopeModule from resteasy.

All the classes that RequestScopeModule binds to a provider are already being bound in JerseyServletModule while creating the injector. Not installing RequestScopeModule is not an option with the current code I'm working with since it enables the objects to be referred using @Context annotation at runtime (and its a third party).

Code looks like:

@Override
protected Injector getInjector()
{
    return Guice.createInjector(new JerseyServletModule()
    {
        @Override
        protected void configureServlets()
        {
            install(new AbcModule());

            //params, filters and other modules

            serve("/*").with(GuiceContainer.class, params);
        }
    });
}

AbcModule.configure:

@Override
protected void configure()
{
    install(new RequestScopeModule());
}

Client code uses @Context UriInfo uriInfo; which is always null in case I do not install RequestScopeModule (since its already bound but not available in the Context). And installing it gives conflicts on all of the classes for which the providers are being created when inserting into the Context of the request.

Is there a way to resolve these conflicts (possibly by removing bindings from JerseyServletModule() and letting guice rebind those from RequestScopeModule)?

Thanks

Nate Bauernfeind

unread,
Oct 20, 2014, 3:27:44 PM10/20/14
to google...@googlegroups.com
Have you tried using AbcModule as an override module?:

@Override
protected Injector getInjector()
{
return Guice.createInjector(Modules.override(new JerseyServletModule()
{
@Override
protected void configureServlets()
{
serve("/*").with(GuiceContainer.class, params);
}
}).with(new AbcModule()));
}

--
You received this message because you are subscribed to the Google Groups "google-guice" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-guice...@googlegroups.com.
To post to this group, send email to google...@googlegroups.com.
Visit this group at http://groups.google.com/group/google-guice.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-guice/b8b3eb6f-b24e-43ec-8813-c2d8ca55c01f%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages