2 Replies Latest reply on Mar 28, 2019 6:19 AM by Iain Macdonald

    Trying to register multiple service locators into single service locator application - Wildfly 15.0.1 with Jersey 2.27

    Iain Macdonald Newbie

      Hi all. We are in this process of investigating moving an application currently running in Weblogic to Wildfly 15.0.1.Final and have run into a bit of an issue.

       

      Our project is an ear which contains multiple wars, two of which are using jersey (2.27) for restful webservices. These are an 'api' war and a 'web' war. The endpoints of which are accessible at "host_name/application/api/" and "host_name/application/web/" respectively.

       

      We are adding our jersey libraries into a lib folder in the ear using the 'earlib' gradle statement (https://docs.gradle.org/current/userguide/ear_plugin.html#sec:ear_dependency_management) and then our wars just use 'providedCompile'. In an effort to allow us to continue using this setup, we have removed jax-rs from our standalone.xml.

       

      If I remove one of these wars from the deployment, it deploys fine and the webservices work as expected. However, if I try to deploy both, we receive an error telling us it is “Trying to register multiple service locators into single service locator application”. The full stacktrace is included below, and I have included our web.xml files for the two wars in question. I'd be happy to provide any other code snippets that may be of use.

       

      Any suggestions on how to get past this issue?

       

      Cheers

       

      Stacktrace:

      17:14:15,716 ERROR [org.jboss.msc.service.fail] (ServerService Thread Pool -- 68) MSC000001: Failed to start service jboss.deployment.subunit."application-core.ear"."application-api.war".undertow-deployment: org.jboss.msc.service.StartException in service jboss.deployment.subunit."application-core.ear"."application-api.war".undertow-deployment: javax.ws.rs.WebApplicationException: Trying to register multiple service locators into single service locator application.
      at org.wildfly.extension.undertow.deployment.UndertowDeploymentService$1.run(UndertowDeploymentService.java:81)
      at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
      at java.util.concurrent.FutureTask.run$$$capture(FutureTask.java:266)
      at java.util.concurrent.FutureTask.run(FutureTask.java)
      at org.jboss.threads.ContextClassLoaderSavingRunnable.run(ContextClassLoaderSavingRunnable.java:35)
      at org.jboss.threads.EnhancedQueueExecutor.safeRun(EnhancedQueueExecutor.java:1985)
      at org.jboss.threads.EnhancedQueueExecutor$ThreadBody.doRunTask(EnhancedQueueExecutor.java:1487)
      at org.jboss.threads.EnhancedQueueExecutor$ThreadBody.run(EnhancedQueueExecutor.java:1378)
      at java.lang.Thread.run(Thread.java:748)
      at org.jboss.threads.JBossThread.run(JBossThread.java:485)
      Caused by: javax.ws.rs.WebApplicationException: Trying to register multiple service locators into single service locator application.
      at org.glassfish.jersey.ext.cdi1x.internal.SingleInjectionManagerStore.registerInjectionManager(SingleInjectionManagerStore.java:64)
      at org.glassfish.jersey.ext.cdi1x.internal.CdiComponentProvider.addInjectionManager(CdiComponentProvider.java:778)
      at org.glassfish.jersey.ext.cdi1x.internal.CdiComponentProvider.initialize(CdiComponentProvider.java:197)
      at org.glassfish.jersey.server.ComponentProviderConfigurator.lambda$null$0(ComponentProviderConfigurator.java:79)
      at java.util.stream.ReferencePipeline$11$1.accept(ReferencePipeline.java:372)
      at java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:193)
      at java.util.ArrayList$ArrayListSpliterator.forEachRemaining(ArrayList.java:1382)
      at java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:481)
      at java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:471)
      at java.util.stream.ReduceOps$ReduceOp.evaluateSequential(ReduceOps.java:708)
      at java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234)
      at java.util.stream.ReferencePipeline.collect(ReferencePipeline.java:499)
      at org.glassfish.jersey.server.ComponentProviderConfigurator.lambda$init$1(ComponentProviderConfigurator.java:80)
      at org.glassfish.jersey.internal.util.collection.Values$LazyValueImpl.get(Values.java:341)
      at org.glassfish.jersey.server.ApplicationConfigurator.createApplication(ApplicationConfigurator.java:122)
      at org.glassfish.jersey.server.ApplicationConfigurator.init(ApplicationConfigurator.java:96)
      at org.glassfish.jersey.server.ApplicationHandler.lambda$initialize$0(ApplicationHandler.java:313)
      at java.util.Arrays$ArrayList.forEach(Arrays.java:3880)
      at org.glassfish.jersey.server.ApplicationHandler.initialize(ApplicationHandler.java:313)
      at org.glassfish.jersey.server.ApplicationHandler.<init>(ApplicationHandler.java:282)
      at org.glassfish.jersey.servlet.WebComponent.<init>(WebComponent.java:335)
      at org.glassfish.jersey.servlet.ServletContainer.init(ServletContainer.java:178)
      at org.glassfish.jersey.servlet.ServletContainer.init(ServletContainer.java:370)
      at javax.servlet.GenericServlet.init(GenericServlet.java:244)
      at io.undertow.servlet.core.LifecyleInterceptorInvocation.proceed(LifecyleInterceptorInvocation.java:117)
      at org.wildfly.extension.undertow.security.RunAsLifecycleInterceptor.init(RunAsLifecycleInterceptor.java:78)
      at io.undertow.servlet.core.LifecyleInterceptorInvocation.proceed(LifecyleInterceptorInvocation.java:103)
      at io.undertow.servlet.core.ManagedServlet$DefaultInstanceStrategy.start(ManagedServlet.java:303)
      at io.undertow.servlet.core.ManagedServlet.createServlet(ManagedServlet.java:143)
      at io.undertow.servlet.core.DeploymentManagerImpl$2.call(DeploymentManagerImpl.java:583)
      at io.undertow.servlet.core.DeploymentManagerImpl$2.call(DeploymentManagerImpl.java:554)
      at io.undertow.servlet.core.ServletRequestContextThreadSetupAction$1.call(ServletRequestContextThreadSetupAction.java:42)
      at io.undertow.servlet.core.ContextClassLoaderSetupAction$1.call(ContextClassLoaderSetupAction.java:43)
      at org.wildfly.extension.undertow.security.SecurityContextThreadSetupAction.lambda$create$0(SecurityContextThreadSetupAction.java:105)
      at org.wildfly.extension.undertow.deployment.UndertowDeploymentInfoService$UndertowThreadSetupAction.lambda$create$0(UndertowDeploymentInfoService.java:1502)
      at org.wildfly.extension.undertow.deployment.UndertowDeploymentInfoService$UndertowThreadSetupAction.lambda$create$0(UndertowDeploymentInfoService.java:1502)
      at org.wildfly.extension.undertow.deployment.UndertowDeploymentInfoService$UndertowThreadSetupAction.lambda$create$0(UndertowDeploymentInfoService.java:1502)
      at org.wildfly.extension.undertow.deployment.UndertowDeploymentInfoService$UndertowThreadSetupAction.lambda$create$0(UndertowDeploymentInfoService.java:1502)
      at org.wildfly.extension.undertow.deployment.UndertowDeploymentInfoService$UndertowThreadSetupAction.lambda$create$0(UndertowDeploymentInfoService.java:1502)
      at io.undertow.servlet.core.DeploymentManagerImpl.start(DeploymentManagerImpl.java:596)
      at org.wildfly.extension.undertow.deployment.UndertowDeploymentService.startContext(UndertowDeploymentService.java:97)
      at org.wildfly.extension.undertow.deployment.UndertowDeploymentService$1.run(UndertowDeploymentService.java:78)
      ... 9 more
      
      
      17:14:18,429 ERROR [org.jboss.as.controller.management-operation] (management-handler-thread - 1) WFLYCTL0013: Operation ("deploy") failed - address: ([("deployment" => "application-core.ear")]) - failure description: {"WFLYCTL0080: Failed services" => {"jboss.deployment.subunit.\"application-core.ear\".\"application-api.war\".undertow-deployment" => "javax.ws.rs.WebApplicationException: Trying to register multiple service locators into single service locator application.
          Caused by: javax.ws.rs.WebApplicationException: Trying to register multiple service locators into single service locator application."}}
      17:14:18,429 ERROR [org.jboss.as.server] (management-handler-thread - 1) WFLYSRV0021: Deploy of deployment "application-core.ear" was rolled back with the following failure message: 
      {"WFLYCTL0080: Failed services" => {"jboss.deployment.subunit.\"application-core.ear\".\"application-api.war\".undertow-deployment" => "javax.ws.rs.WebApplicationException: Trying to register multiple service locators into single service locator application.
          Caused by: javax.ws.rs.WebApplicationException: Trying to register multiple service locators into single service locator application."}}
      [2019-03-20 05:14:18,850] Artifact application-core.ear: Error during artifact deployment. See server log for details.
      [2019-03-20 05:14:18,850] Artifact application-core.ear: java.lang.Exception: {"WFLYCTL0080: Failed services" => {"jboss.deployment.subunit.\"application-core.ear\".\"application-api.war\".undertow-deployment" => "javax.ws.rs.WebApplicationException: Trying to register multiple service locators into single service locator application.
          Caused by: javax.ws.rs.WebApplicationException: Trying to register multiple service locators into single service locator application."}}
      

       

      API web.xml:

      <?xml version="1.0" encoding="UTF-8"?>
      <web-app xmlns="http://java.sun.com/xml/ns/javaee"
               xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
               xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
        http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
               version="2.5">
      
      
          <display-name>Application REST API</display-name>
      
      
          <welcome-file-list>
              <welcome-file>index.jsp</welcome-file>
          </welcome-file-list>
      ...
          <servlet>
              <display-name>REST API</display-name>
              <servlet-name>ApplicationApiApp</servlet-name>
              <servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class>
              <init-param>
                  <param-name>javax.ws.rs.Application</param-name>
                  <param-value>com.test.application.core.apiservice.api.app.ApplicationApiApp</param-value>
              </init-param>
              <!-- Register resources and providers under  "infrastructure" package. -->
              <init-param>
                  <param-name>jersey.config.server.provider.packages</param-name>
                  <param-value>
                      io.swagger.v3.jaxrs2.integration.resources,
                      com.test.application.core.apiservice.api.infrastructure
                  </param-value>
              </init-param>
              <init-param>
                  <param-name>openApi.configuration.prettyPrint</param-name>
                  <param-value>true</param-value>
              </init-param>
              <init-param>
                  <param-name>jersey.config.server.provider.classnames</param-name>
                  <param-value>
                      org.glassfish.jersey.jackson.JacksonFeature;org.glassfish.jersey.media.multipart.MultiPartFeature
                  </param-value>
              </init-param>
              <init-param>
                  <param-name>jersey.config.server.monitoring.statistics.enabled</param-name>
                  <param-value>false</param-value>
              </init-param>
              <load-on-startup>1</load-on-startup>
          </servlet>
          <servlet-mapping>
              <servlet-name>ApplicationApiApp</servlet-name>
              <url-pattern>/*</url-pattern>
          </servlet-mapping>
      </web-app>
      

       

      Web web.xml:

      <?xml version="1.0" encoding="UTF-8"?>
      <web-app xmlns="http://java.sun.com/xml/ns/javaee"
               xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
               xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
        http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
               version="2.5">
      
      
          <display-name>Application WEB</display-name>
      
      
          <welcome-file-list>
              <welcome-file>index.jsp</welcome-file>
          </welcome-file-list>
      
      
          ...
      
      
          <servlet>
              <display-name>Application Web App</display-name>
              <servlet-name>ApplicationWebApp</servlet-name>
              <servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class>
              <init-param>
                  <param-name>javax.ws.rs.Application</param-name>
                  <param-value>com.test.application.web.app.ApplicationWebApp</param-value>
              </init-param>
              <!-- Register resources and providers under  "infrastructure" package. -->
              <init-param>
                  <param-name>jersey.config.server.provider.packages</param-name>
                  <param-value>
                      io.swagger.v3.jaxrs2.integration.resources,
                      com.test.application.web
                  </param-value>
              </init-param>
              <init-param>
                  <param-name>openApi.configuration.prettyPrint</param-name>
                  <param-value>true</param-value>
              </init-param>
              <init-param>
                  <param-name>jersey.config.server.provider.classnames</param-name>
                  <param-value>
                      org.glassfish.jersey.jackson.JacksonFeature;org.glassfish.jersey.media.multipart.MultiPartFeature
                  </param-value>
              </init-param>
              <init-param>
                  <param-name>jersey.config.server.monitoring.statistics.enabled</param-name>
                  <param-value>false</param-value>
              </init-param>
              <load-on-startup>1</load-on-startup>
          </servlet>
          <servlet-mapping>
              <servlet-name>ApplicationWebApp</servlet-name>
              <url-pattern>/*</url-pattern>
          </servlet-mapping>
      </web-app>