Jboss EAP 6.1中的RestEasy冲突

时间:2014-02-04 08:14:17

标签: java jboss jersey jax-rs resteasy

我正在尝试使用Jersey来创建RESTful API。我的pom.xml看起来像:

<!-- Jersey Library -->
        <dependency>
            <groupId>com.sun.jersey</groupId>
            <artifactId>jersey-server</artifactId>
            <version>1.18</version>
        </dependency>
        <dependency>
            <groupId>com.sun.jersey</groupId>
            <artifactId>jersey-bundle</artifactId>
            <version>1.18</version>
        </dependency>
        <dependency>
            <groupId>asm</groupId>
            <artifactId>asm</artifactId>
            <version>3.3.1</version>
        </dependency>

但是在Jboss中部署应用程序时出现Only one JAX-RS Application Class allowed.异常。但是,这在tomcat的情况下非常有效。

Stacktrace:

ERROR [org.jboss.msc.service.fail] (MSC service thread 1-2) MSC000001: Failed to start service jboss.deployment.unit."apiinterface.war".POST_MODULE: org.jboss.msc.service.StartException in service jboss.deployment.unit."apiinterface.war".POST_MODULE: JBAS018733: Failed to process phase POST_MODULE of deployment "apiinterface.war"
        at org.jboss.as.server.deployment.DeploymentUnitPhaseService.start(DeploymentUnitPhaseService.java:127) [jboss-as-server-7.2.0.Final-redhat-4.jar:7.2.0.Final-redhat-4]
        at org.jboss.msc.service.ServiceControllerImpl$StartTask.startService(ServiceControllerImpl.java:1811) [jboss-msc-1.0.4.GA-redhat-1.jar:1.0.4.GA-redhat-1]
        at org.jboss.msc.service.ServiceControllerImpl$StartTask.run(ServiceControllerImpl.java:1746) [jboss-msc-1.0.4.GA-redhat-1.jar:1.0.4.GA-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: JBAS011232: Only one JAX-RS Application Class allowed.  com.sun.jersey.api.core.ClasspathResourceConfig com.sun.jersey.api.core.DefaultResourceConfig com.sun.jersey.server.impl.application.DeferredResourceConfig com.sun.jersey.api.core.servlet.WebAppResourceConfig com.sun.jersey.api.core.DefaultResourceConfig com.sun.jersey.api.core.ApplicationAdapter com.sun.jersey.api.core.ClassNamesResourceConfig com.sun.jersey.api.core.ResourceConfig com.sun.jersey.api.core.ApplicationAdapter com.sun.jersey.api.core.ClasspathResourceConfig com.sun.jersey.server.impl.application.DeferredResourceConfig com.sun.jersey.api.core.ScanningResourceConfig com.sun.jersey.api.core.ScanningResourceConfig com.sun.jersey.api.core.PackagesResourceConfig com.sun.jersey.api.core.ClassNamesResourceConfig com.sun.jersey.api.core.PackagesResourceConfig com.sun.jersey.api.core.ResourceConfig
        at org.jboss.as.jaxrs.deployment.JaxrsScanningProcessor.scan(JaxrsScanningProcessor.java:206)
        at org.jboss.as.jaxrs.deployment.JaxrsScanningProcessor.deploy(JaxrsScanningProcessor.java:104)
        at org.jboss.as.server.deployment.DeploymentUnitPhaseService.start(DeploymentUnitPhaseService.java:120) [jboss-as-server-7.2.0.Final-redhat-4.jar:7.2.0.Final-redhat-4]
        ... 5 more

我尝试实施Deploying a Jersey webapp on Jboss AS 7的答案但到目前为止没有成功。

2 个答案:

答案 0 :(得分:5)

JBoss AS / EAP已经为您提供了JAX-RS实现(RESTEasy),因此您的pom.xml应该只包含对JAX-RS API的依赖(范围为provided)。

如果要在Tomcat和/或JBoss AS上构建和部署,则应使用Maven配置文件并仅在Tomcat配置文件中包含Jersey artefacts。

答案 1 :(得分:0)

JBoss不支持Jersey Out Of the Box,它有自己的实现RestEasy, 为了使Jersey工作,我们需要在standalone.xml中禁用Jersey,并启用ReastEasy支持。