繁体   English   中英

将应用程序从RestEasy迁移到Jersey

[英]Migrating application from RestEasy to Jersey

我正在将应用程序从RestEasy实施迁移到Jersey实施。 我面临的主要问题是CDI零件所需的罐子。
在使用resteasy时,我们正在使用以下3个resteasy相关罐子

<dependency>
        <groupId>org.jboss.resteasy</groupId>
        <artifactId>resteasy-cdi</artifactId>
        <version>3.0.8-FINAL</version>
</dependency>
<dependency>
    <groupId>org.jboss.resteasy</groupId>
    <artifactId>resteasy-jaxrs</artifactId>
    <version>3.0.8-FINAL</version>
</dependency>
<dependency>
    <groupId>org.jboss.resteasy</groupId>
    <artifactId>resteasy-servlet-initializer</artifactId>
    <version>3.0.8-FINAL</version>
</dependency>

现在,要将其迁移到Jersey,我使用以下jar代替resteasy jar。

<dependency>
    <groupId>org.glassfish.jersey.containers</groupId>
    <artifactId>jersey-container-servlet</artifactId>
    <version>2.22.1</version>
</dependency>
<dependency>
    <groupId>org.glassfish.jersey.ext.cdi</groupId>
    <artifactId>jersey-cdi1x-servlet</artifactId>
    <version>2.22.1</version>
</dependency>
<dependency>
    <groupId>javax.enterprise</groupId>
    <artifactId>cdi-api</artifactId>
    <version>1.1</version>
</dependency>

现在,当我尝试在JBOSS服务器上部署EAR时,出现以下错误。

15:04:48,156 ERROR [org.jboss.msc.service.fail] (MSC service thread 1-5) MSC000001: Failed to start service jboss.deployment.subunit."abc-ear.ear"."xyz-service-impl.war".POST_MODULE: org.jboss.msc.service.StartException in service jboss.deployment.subunit."abc-ear.ear"."xyz-service-impl.war".POST_MODULE: JBAS018733: Failed to process phase POST_MODULE of subdeployment "xyz-service-impl.war" of deployment "abc-ear.ear"
at org.jboss.as.server.deployment.DeploymentUnitPhaseService.start(DeploymentUnitPhaseService.java:166) [jboss-as-server-7.4.0.Final-redhat-19.jar:7.4.0.Final-redhat-19]
at org.jboss.msc.service.ServiceControllerImpl$StartTask.startService(ServiceControllerImpl.java:1980) [jboss-msc-1.1.5.Final-redhat-1.jar:1.1.5.Final-redhat-1]
at org.jboss.msc.service.ServiceControllerImpl$StartTask.run(ServiceControllerImpl.java:1913) [jboss-msc-1.1.5.Final-redhat-1.jar:1.1.5.Final-redhat-1]
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145) [rt.jar:1.7.0_45]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615) [rt.jar:1.7.0_45]
at java.lang.Thread.run(Thread.java:744) [rt.jar:1.7.0_45]
Caused by: org.jboss.as.server.deployment.DeploymentUnitProcessingException: JBAS016053: Service class org.glassfish.jersey.ext.cdi1x.internal.CdiComponentProvider didn't implement the javax.enterprise.inject.spi.Extension interface
at org.jboss.as.weld.deployment.WeldPortableExtensions.tryRegisterExtension(WeldPortableExtensions.java:48)
at org.jboss.as.weld.deployment.processors.WeldPortableExtensionProcessor.loadAttachments(WeldPortableExtensionProcessor.java:119)
at org.jboss.as.weld.deployment.processors.WeldPortableExtensionProcessor.deploy(WeldPortableExtensionProcessor.java:79)
at org.jboss.as.server.deployment.DeploymentUnitPhaseService.start(DeploymentUnitPhaseService.java:159) [jboss-as-server-7.4.0.Final-redhat-19.jar:7.4.0.Final-redhat-19]
... 5 more

从堆栈跟踪中可以看到,我得到的错误是org.glassfish.jersey.ext.cdi1x.internal.CdiComponentProvider didn't implement the javax.enterprise.inject.spi.Extension interface

我下载了所需jar的源代码,以查看所讨论的类是否实现了该接口。 好吧,它确实实现了扩展接口。

目前,我无法找到此错误的解决方案。
我尝试了各种球衣瓶的各种排列和组合,但找不到解决方法。
我的想法已经用光了。 任何帮助将非常感激。

最近,我完成了非常类似的迁移(RESTEasy 3.0.8.Final-> Jersey 2.23.1),但是我的迁移也包括放弃WildFly服务器。 因此,差异很大。

您尚未提供有关二手Weld版本的任何信息,因此请执行此操作,因为这在此处非常重要。

无论如何,在您更新问题之前,有两个我的建议:

  • 您的错误很有可能是由EAR部署引起的。 因为CDI和EAR档案有时不能很好地配合使用。 如果将包装更改为* .war,可以检查发生什么情况吗?
  • 如果在使用Java EE应用服务器和CDI时没有非常非常好的理由迁移到非内置的JAX-RS实现,请不要这样做。 这是一项艰巨的任务。

附言 我遇到的JFYI与Weld和App服务器有关的问题促使我尽可能地放弃它们。

更新

您说您正在使用Weld 1.1.23.FINAL这是非常重要的信息。 自Jersey 2.15起,Jersey + Weld集成发生了重大变化。 就个人而言,如果没有一些较新的Weld版本(在我的情况下为2.3.5),我将无法使其工作-可能是因为不支持此组合。 在您的情况下,由于您使用的焊接版本非常旧,我建议您最多尝试Jersey 2.14。

在Jersey 2.14中,所需的依赖项有所不同。 请删除jersey-cdi1x-servlet然后尝试以下操作:

<dependency>
  <groupId>org.glassfish.jersey.containers.glassfish</groupId>
  <artifactId>jersey-gf-cdi</artifactId>
  <version>2.14</version>
</dependency>
<dependency>
  <groupId>org.glassfish.jersey.containers.glassfish</groupId>
  <artifactId>jersey-gf-cdi-ban-custom-hk2-binding</artifactId>
  <version>2.14</version>
</dependency>

<!-- is it needed for you?
<dependency>
  <groupId>org.jboss.weld.servlet</groupId>
  <artifactId>weld-servlet-core</artifactId>
</dependency>
-->

顺便说一句:我是否知道您为什么要在JBoss中更改JAX-RS实现?

我上个月已迁移到最新版本,这对我有用。 尝试这个。

<properties>
    <version.jersey>2.23.2</version.jersey>
    <version.glassfish>2.4.0</version.glassfish>
</properties>

<dependencies>
    <dependency>
        <groupId>org.glassfish.hk2.external</groupId>
        <artifactId>asm-all-repackaged</artifactId>
        <version>${version.glassfish}</version>
    </dependency>

    <dependency>
        <artifactId>hk2-utils</artifactId>
        <groupId>org.glassfish.hk2</groupId>
        <version>${version.glassfish}</version>
        <exclusions>
            <exclusion>
                <artifactId>javax.inject</artifactId>
                <groupId>javax.inject</groupId>
            </exclusion>
        </exclusions>
    </dependency>

    <dependency>
        <groupId>javax.annotation</groupId>
        <artifactId>javax.annotation-api</artifactId>
        <version>1.2</version>
    </dependency>

    <dependency>
        <groupId>javax.ws.rs</groupId>
        <artifactId>javax.ws.rs-api</artifactId>
        <version>2.0.1</version>
    </dependency>

    <dependency>
        <groupId>javax.xml.bind</groupId>
        <artifactId>jaxb-api</artifactId>
        <version>2.2.12</version>
    </dependency>

    <dependency>
        <groupId>org.glassfish.jersey.core</groupId>
        <artifactId>jersey-common</artifactId>
        <version>${version.jersey}</version>
        <exclusions>
            <exclusion>
                <groupId>org.glassfish.hk2</groupId>
                <artifactId>osgi-resource-locator</artifactId>
            </exclusion>
            <exclusion>
                <groupId>org.glassfish.hk2.external</groupId>
                <artifactId>aopalliance-repackaged</artifactId>
            </exclusion>                            
        </exclusions>
    </dependency>
    <dependency>
        <groupId>org.glassfish.jersey.containers</groupId>
        <artifactId>jersey-container-servlet</artifactId>
        <version>${version.jersey}</version>
    </dependency>

    <dependency>
        <groupId>org.glassfish.jersey.media</groupId>
        <artifactId>jersey-media-multipart</artifactId>
        <version>${version.jersey}</version>
    </dependency>
</dependencies>

您可能使用了错误的依赖关系。 检查以下内容: https : //jersey.java.net/documentation/latest/modules-and-dependencies.html

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM