Note that there are some explanatory texts on larger screens.

plurals
  1. POGuice - Jersey - Servlet binding
    primarykey
    data
    text
    <p>I recently switched to two phase injection and this has created an error in my servlet binding. I am currently toggling between two error modes and not sure which direction is best to pursue.</p> <p>The first error I encountered was:</p> <blockquote> <p>com.sun.jersey.api.container.ContainerException: The ResourceConfig instance does not contain any root resource classes.</p> </blockquote> <p>My servlet module looked like this:</p> <pre><code>public class MyServletModule extends JerseyServletModule { @Override protected void configureServlets() { bind(MyServlet.class).asEagerSingleton(); serve("/*").with(GuiceContainer.class); } } </code></pre> <p>I was able to remove this error by explicitly providing the com.sun.jersey.config.property.packages parameter.</p> <pre><code>public class MyServletModule extends JerseyServletModule { @Override protected void configureServlets() { bind(MyServlet.class).asEagerSingleton(); Map&lt;String,String&gt; parameters = new HashMap&lt;String, String&gt;(); parameters.put(PackagesResourceConfig.PROPERTY_PACKAGES, MyServlet.class.getPackage().getName()); serve("/*").with(GuiceContainer.class, parameters); } } </code></pre> <p>But when I do this, Guice attempts a Just in Time binding which does not respect the @Inject on my servlet constructor.</p> <blockquote> <p>com.google.inject.ConfigurationException: Guice configuration errors:</p> <p>1) Unable to create binding for MyServlet. It was already configured on one or more child injectors or private modules bound at MyServletModule.configureServlets(MyServletModule.java:44) If it was in a PrivateModule, did you forget to expose the binding? while locating MyServlet</p> <p>1 error at com.google.inject.internal.InjectorImpl.getBinding(InjectorImpl.java:150)</p> </blockquote> <p>My servlet has an @Inject constructor who's arguments cannot be bound just in time. After debugging into InjectorImpl, I believe this is the reason that things fail when I use PROPERTY_PACKAGES.</p> <p>I'm just not sure if using PROPERTY_PACKAGES is correct and I need to fix some bindings? Or if that is the wrong direction and I need to fix the original ResourceConfig error in a different way.</p> <p>Help or a push in the right direction is appreciated.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload