Wildfly 15和Jersey-尝试将多个服务定位器注册到单个服务定位器应用程序中

时间:2019-03-21 13:03:53

标签: java-ee jersey wildfly jersey-2.0 hk2

我们正在研究将当前在Weblogic上运行的应用程序移至Wildfly 15.0.1.Final

我们的项目是一个包含多个战争的耳朵,其中两个战争利用Jersey(2.27)来实现稳定的Web服务。这是“ api”战争和“ web”战争,它们的端点可以分别在“ host_name / application / api /”和“ host_name / application / web /”进行访问。

我们目前正在使用'earlib'gradle语句将球衣库添加到耳朵的lib文件夹中,而我们的战争则使用'providedCompile'。为了使我们能够继续使用此设置,我们从standalone.xml中删除了jax-rs。

如果我从部署中删除这些冲突之一,则它部署良好,并且Web服务可以按预期工作。但是,如果我尝试同时部署两者,则会收到一条错误消息,告诉我们它是Trying to register multiple service locators into single service locator application。完整的stacktrace包含在下面,并且我还包含了涉及上述两次战争的web.xml文件。

关于如何解决此问题的任何建议?我很乐意提供其他可能有用的代码段或信息。

欢呼

堆栈跟踪:

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>

1 个答案:

答案 0 :(得分:1)

默认情况下,泽西岛使用*Single*InjectionManagerStore

/**
 * Default {@link InjectionManagerStore injection manager} that assumes only one
 * {@link InjectionManager injection manager} per application is used.
 */

您可以通过创建放置在META-INF / services下的平面文件“ org.glassfish.jersey.ext.cdi1x.internal.spi.InjectionManagerStore”来切换到备用impl。该文件必须包含一行,并带有所选impl的类名。您也许可以尝试使用'ServletInjectionManagerStore'

查看完整示例here

还请注意以下注释:“ 在单个WAR / JVM中启用了多个Jersey应用”:-)

祝你好运