Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Jersey + Guice + Swagger seems to be playing bad. #1748

Closed
blommish opened this issue Apr 12, 2016 · 1 comment
Closed

Jersey + Guice + Swagger seems to be playing bad. #1748

blommish opened this issue Apr 12, 2016 · 1 comment

Comments

@blommish
Copy link

I have an application running Jersey (2.22.1) + Guice.

Once I just add the dependency to swagger(swagger-jersey2-jaxrs 1.5.0), it fails to start the server - just getting a weird stack dump

-----Start of DE processing------ = [4/12/16 16:36:14:909 CEST] Exception = com.ibm.ws.container.service.state.StateChangeException Source = com.ibm.ws.app.manager.web.internal.WebModuleHandlerImpl probeid = 104 Stack Dump = com.ibm.ws.container.service.state.StateChangeException: com.ibm.ws.container.service.state.StateChangeException: startWebApplication at com.ibm.ws.webcontainer.osgi.WebContainer.startModule(WebContainer.java:835) at com.ibm.ws.app.manager.web.internal.WebModuleHandlerImpl.deployModule(WebModuleHandlerImpl.java:103) at com.ibm.ws.app.manager.module.internal.DeployedAppInfoBase.deployModule(DeployedAppInfoBase.java:871) at com.ibm.ws.app.manager.module.internal.DeployedAppInfoBase.deployModules(DeployedAppInfoBase.java:831) at com.ibm.ws.app.manager.module.internal.DeployedAppInfoBase.deployApp(DeployedAppInfoBase.java:818) at com.ibm.ws.app.manager.war.internal.WARApplicationHandlerImpl.install(WARApplicationHandlerImpl.java:66) at com.ibm.ws.app.manager.internal.statemachine.StartAction.execute(StartAction.java:141) at com.ibm.ws.app.manager.internal.statemachine.ApplicationStateMachineImpl.enterState(ApplicationStateMachineImpl.java:1192) at com.ibm.ws.app.manager.internal.statemachine.ApplicationStateMachineImpl.run(ApplicationStateMachineImpl.java:805) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1143) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:618) at java.lang.Thread.run(Thread.java:785) Caused by: com.ibm.ws.container.service.state.StateChangeException: startWebApplication at com.ibm.ws.webcontainer.osgi.WebContainer.startModule(WebContainer.java:825) ... 11 more

My application extends an abstract class which contains among other things:

public CommonApplication(ServiceLocator serviceLocator) {
    LOG.info("Initializing service");

    if (getPackagesToBeScannedByJersey() != null) {
        packages(getPackagesToBeScannedByJersey());
    }

    GuiceBridge.getGuiceBridge().initializeGuiceBridge(serviceLocator);
    GuiceIntoHK2Bridge guiceBridge = serviceLocator.getService(GuiceIntoHK2Bridge.class);

    List<Module> modules = createListOfModules();

    registerFilters();

    Injector app = Guice.createInjector(modules);
    guiceBridge.bridgeGuiceInjector(app);
    Config.setConfigFile(getAppName() + ".Config.properties");
}

web.xml

    <display-name>TestServiceApplication</display-name>

  <servlet>
    <servlet-name>Jersey Web Application</servlet-name>
    <servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class>

    <init-param>
      <param-name>javax.ws.rs.Application</param-name>
      <param-value>test.services.template.TestServiceApplication</param-value>
    </init-param>

    <init-param>
      <!-- With WebSphere, to see the service response in case of errors instead of the
      Websphere default error page, Jersey has to be configured in this way.
      https://java.net/jira/browse/JERSEY-2521 -->
      <param-name>jersey.config.server.response.setStatusOverSendError</param-name>
      <param-value>true</param-value>
    </init-param>
    <load-on-startup>1</load-on-startup>
  </servlet>
  <servlet-mapping>
    <servlet-name>Jersey Web Application</servlet-name>
    <url-pattern>/api/*</url-pattern>
  </servlet-mapping>


  <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>/api/*</url-pattern>
  </filter-mapping>

Dependencies:

<dependency>
  <groupId>com.google.inject.extensions</groupId>
  <artifactId>guice-servlet</artifactId>
  <version>3.0</version>
</dependency>
<dependency>
  <groupId>org.glassfish.hk2</groupId>
  <artifactId>guice-bridge</artifactId>
  <version>2.4.0-b31</version>
</dependency>
<dependency>
  <groupId>com.google.inject.extensions</groupId>
  <artifactId>guice-multibindings</artifactId>
  <version>3.0</version>
</dependency>

#1619

@blommish
Copy link
Author

Sorry, this can be closed. Found our by reading the wiki here that I might need to exclude jersey version. That was the solution.

Can be closed

@webron webron closed this as completed Apr 12, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants