【问题标题】:Jetty 9.3.9.v20160517 Provider WebSocketCdiInitializer not found when enabling Annotations启用注释时找不到 Jetty 9.3.9.v20160517 Provider WebSocketCdiInitializer
【发布时间】:2016-06-06 13:37:38
【问题描述】:

使用 DeploymentManager 部署 webapp 时,会抛出此错误

2016-06-06 15:19:37,750 WARN  [org.eclipse.jetty.deploy.DeploymentManager] (WrapperSimpleAppMain) Unable to reach node goal: started (DeploymentManager.java:506)
java.util.ServiceConfigurationError: javax.servlet.ServletContainerInitializer: Provider org.eclipse.jetty.cdi.websocket.WebSocketCdiInitializer not found
    at java.util.ServiceLoader.fail(ServiceLoader.java:239)
    at java.util.ServiceLoader.access$300(ServiceLoader.java:185)
    at java.util.ServiceLoader$LazyIterator.nextService(ServiceLoader.java:372)
    at java.util.ServiceLoader$LazyIterator.next(ServiceLoader.java:404)
    at java.util.ServiceLoader$1.next(ServiceLoader.java:480)
    at org.eclipse.jetty.annotations.AnnotationConfiguration.getNonExcludedInitializers(AnnotationConfiguration.java:864)
    at org.eclipse.jetty.annotations.AnnotationConfiguration.configure(AnnotationConfiguration.java:444)
    at org.eclipse.jetty.webapp.WebAppContext.configure(WebAppContext.java:494)
    at org.eclipse.jetty.webapp.WebAppContext.startContext(WebAppContext.java:1361)
    at org.eclipse.jetty.server.handler.ContextHandler.doStart(ContextHandler.java:772)
    at org.eclipse.jetty.servlet.ServletContextHandler.doStart(ServletContextHandler.java:262)
    at org.eclipse.jetty.webapp.WebAppContext.doStart(WebAppContext.java:520)
    at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:68)

在启用注释支持时会发生这种情况:

    org.eclipse.jetty.webapp.Configuration.ClassList classlist = org.eclipse.jetty.webapp.Configuration.ClassList.setServerDefault(server);
    classlist.addBefore(
        "org.eclipse.jetty.webapp.JettyWebXmlConfiguration",
        "org.eclipse.jetty.annotations.AnnotationConfiguration"
    );
    classlist.addAfter(
        "org.eclipse.jetty.webapp.FragmentConfiguration",
        "org.eclipse.jetty.plus.webapp.PlusConfiguration"
    );

jar cdi-websocket-9.3.9.v20160517.jar 在类路径中

这个issue 建议停用cdi Jetty 模块,但没有说明如何使用嵌入式Jetty。

我该如何解决这个问题?

编辑

我们意识到这个问题可能是由应用程序运行的(复杂)环境引起的。

因此,我特别有兴趣了解什么可能导致引发此异常的根本原因

结论

TD;LR:Jetty-9.3.9 嵌入式!= Jetty-9.3.9 独立

在 Jetty 9.2.14 中,我们以编程方式启动 Jetty(就像嵌入的 Jetty),但使用的是独立 Jetty 的未打包版本的 jar。

自 Jetty 7(甚至可能是 6)以来,我们的设置运行良好,但升级到 Jetty 9.3.9 时,情况开始出现问题。

注意:我们使用的是 Jersey、servlet 和极少数的 JSP。没有网络套接字。我们正在升级以测试 HTTP/2。

【问题讨论】:

  • 其实更好的说法是jetty-cdi-*是专门为独立的jetty-distribution及其模块系统设计的。当您在embedded-jetty 中时,使用它过于复杂(而且毫无意义)。更简单的解决方案是直接使用cdi-weld

标签: java jetty jetty-9


【解决方案1】:

既然你说你是jetty-embedded,那么解决方法很简单。

不要在您的项目中包含 jetty-cdi-* jar。 它们不适用于嵌入式码头。

直接从焊接项目中为 Jetty Embedded 使用 cdi-weld 工件。

请务必阅读焊接文档,了解如何设置 WebAppClassloader 以允许焊接查看服务器组件。 (这叫“在webapp隔离层上打个洞”)

【讨论】:

  • 谢谢。我不会忘记你:我们正在运行测试并会给你反馈
  • 我将根据我们的发现编辑我的问题。这两个答案实际上都提供了关于做什么的提示;你的比另一个多,所以我把它授予你。谢谢
【解决方案2】:

来自Jetty 9.3.2的源代码[1](估计到了9.3.9后行没变)我找到了如下源码sn-p:

851         //Get initial set of SCIs that aren't from excluded jars or excluded by the containerExclusionPattern, or excluded
852         //because containerInitializerOrdering omits it
853         for (ServletContainerInitializer sci:loadedInitializers)
854         {       
855             if (matchesExclusionPattern(sci)) 
856             {
857                 if (LOG.isDebugEnabled()) LOG.debug("{} excluded by pattern", sci);
858                 continue;
859             }
860             
861             Resource sciResource = getJarFor(sci);
862             if (isFromExcludedJar(context, sci, sciResource)) 
863             { 
864                 if (LOG.isDebugEnabled()) LOG.debug("{} is from excluded jar", sci);
865                 continue;
866             }

那里的评论告诉我们这里检查了 SCI (ServletContainerInitializer) 是否被任何原因排除在外。您的堆栈跟踪告诉我们第 864 行正在引发异常。 LOG.debug 试图说明原因是 SCI 来自排除的 jar 从而导致您遇到的错误。

我的建议是你检查你的 maven 配置(你的 pom.xml)关于包含 org.eclipse.jetty.annotations.AnnotationConfiguration 文件的包:

<!-- http://mvnrepository.com/artifact/org.eclipse.jetty/jetty-annotations -->
<dependency>
   <groupId>org.eclipse.jetty</groupId>
   <artifactId>jetty-annotations</artifactId>
   <version>9.3.9.M1</version>
</dependency>

[2] 并且这种依赖并没有从一些奇怪的原因中排除。我想 jar 是指 maven 依赖项。

我的来源:

[1] http://grepcode.com/file/repo1.maven.org/maven2/org.eclipse.jetty/jetty-annotations/9.3.2.v20150730/org/eclipse/jetty/annotations/AnnotationConfiguration.java?av=f

[2] http://mvnrepository.com/artifact/org.eclipse.jetty/jetty-annotations/9.3.9.M1

【讨论】:

  • 谢谢。我不会忘记你:我们正在运行测试并会给你反馈
  • 我将根据我们的发现编辑我的问题。这两个答案实际上都提供了关于做什么的提示; @Joakim Erdfelt 比你的多,所以我将它授予他。感谢您的宝贵时间
猜你喜欢
  • 2014-10-29
  • 1970-01-01
  • 2014-11-06
  • 1970-01-01
  • 2017-11-14
  • 1970-01-01
  • 1970-01-01
  • 2017-02-01
  • 1970-01-01
相关资源
最近更新 更多