Guice Integration with Jersey (square): ServiceLocatorGenerator not installed

I am using an Android app version 2.22 that I am trying to integrate with Guice 4.0 using the Squarespace jersey2-guice-impl library so that I can easily inject Guice dependencies into my controllers.

(My apologies for the minor typos below, I had to retype everything.)

But I get the following startup errors resulting from my WebListener:

   SEVERE: Exception starting filter jersey
   java.lang.IllegalStateException: It appears there is no ServiceLocatorGenerator installed.  
     at com.squarespace.jersey2.guice.GuiceServiceLocatorGeneratorStub.create(GuiceServiceLocatortGeneratorStub.java:50)
     at org.glassifsh.hk3.internal.ServiceLocatorFactoryImpl.internalCreate(ServiceLocatorFactoryImpl.java:312)
     at org.glassfish.h2k.internal.ServiceLocatorFactoryimpl.create(ServiceLocatorFactoryImpl.java: 268)
     at org.glassfish.jersey.internal.inject.Injections._createLocator(Injections.java:138)
     at org.glassfish.internal.inject.Injections.createLocator(Injections.java:123)
     at org.glassfish.jersey.server.ApplicationHandler.<init>(WebComponent.java:392)
     at org.glassfish.jersey.servlet.ServletContainer.init(ServletContainer.java:177)
     at org.glassfish.jersey.servlet.ServletContainer.init(ServletContainer:415)
     at org.apache.catalina.core.ApplicationFilterConfig.initFilter(ApplicationFilterConfig.java:281)
     at org.apache.catalina.core.ApplicationFilterConfig.getFilter(ApplicationFilterConfig.java: 262)
     at ....

I use the following dependencies from my pom.xml:

 <dependency>
    <groupId>com.google.guava</groupId>
    <artifactId>guice</artifactId>
    <version>4.0.0</version>
 </dependency>
 <dependency>
    <groupId>com.google.inject.extensions</groupId>
    <artifactId>guice-servlet</artifactId>
    <version>4.0.0</version>
 </dependency>
 <dependency>
    <groupId>com.squarespace.jersey2-guice</groupId>
    <artifactId>jersey2-guice-impl</artifactId>
    <version>1.0.6</version>
 </dependency>
 <dependency>
    <groupId>org.glassfish.jersey.containers</groupId>
    <artifactId>jersey-container-servlet</artifactId>
    <version>2.22.2</version>
 </dependency>
 <dependency>
    <groupId>org.glassfish.jersey.core</groupId>
    <artifactId>jersey-container-servlet</artifactId>
    <version>2.22.2</version>
 </dependency>
 <dependency>
    <groupId>org.glassfish.jersey.media</groupId>
    <artifactId>jersey-media-multipart</artifactId>
    <version>2.22.2</version>
 </dependency>
 <dependency>
    <groupId>org.glassfish.jersey.ext</groupId>
    <artifactId>jersey-mvc</artifactId>
    <version>2.22.1</version>
 </dependency>

And this is WebListener:

@WebListener
public class FakeResourceManager extends GuiceServletContextListener{
      @Override protected Injector getInjector(){
           return Guice.createInjector(new ArrayList<Module>());
      }
}

And this is web.xml

<filter>
     <filter-name>GuiceFilter</filter-name>
     <filter-class>com.google.inject.servlet.GuiceFilter</filter-class>
</filter>
<filter-mapping>
     <filter-name>GuiceFilter</filter-name>
     <url-pattern>/*</url-pattern>
</filter-mapping>
<filter>
     <filter-name>jersey</filter-name>
     <filter-class>org.glassfish.jersey.servlet.ServletContainer</filter-class>
     <init-param>
        <param-name>jersey.config.server.provider.packages</param-name>
        <param-value>mypackage.rest;guice.tomcat.jersey</param-value>
     </init-param>
     <init-param>
        <param-name>jersey.config.server.provider.classnames</param-name>
        <param-value>org.glassfish.jersey.media.multipart.MultiPartFeature;org.glassfish.jersey.server.mvc.jsp.JspMvcFeature</param-value>
     </init-param>
</filter>
<filter-mapping>
  <filter-name>jersey</filter-name>
  <url-pattern>/*</url-pattern>
</filter-mapping>

I host in Tomcat 7.0.42.

It seems very simple. I think that when loading, there might be a problem with ordering. Perhaps the call to install ServiceLocatorGenerator does not occur until the filter is loaded. How can I make this happen? What am I missing?

+4

All Articles