在Jboss AS 7上部署Jersey webapp

时间:2011-08-05 08:33:52

标签: jboss migration jersey jboss7.x

目前在Jboss AS 4/5上运行一些webapps,我正在测试迁移到jboss7。当我尝试在JBoss AS 7上部署基于jersey的webapp(带有独立预览配置文件的完整配置文件)时,我得到:

org.jboss.as.server.deployment.DeploymentUnitProcessingException: Only one JAX-RS Application Class allowed.

我已经做了一些搜索,发现RestEasy是嵌入到Application Server中的默认JAX-RS实现。像http://community.jboss.org/message/579996https://issues.jboss.org/browse/JBAS-8830这样的帖子提到RestEasy部署者接管了。

在AS 6中,删除部署者似乎更容易,而我还没有看到AS 7的任何解决方案。

11 个答案:

答案 0 :(得分:69)

在这篇文章中已经提到过:https://community.jboss.org/message/744530#744530,你可以要求resteasy模块不要在你的webapp中扫描其他JAX RS实现;只需将其添加到您的web.xml:

<context-param>
    <param-name>resteasy.scan</param-name>
    <param-value>false</param-value>
</context-param>
<context-param>
    <param-name>resteasy.scan.providers</param-name>
    <param-value>false</param-value>
</context-param>
<context-param>
    <param-name>resteasy.scan.resources</param-name>
    <param-value>false</param-value>
</context-param>

对我来说很好

答案 1 :(得分:6)

除了删除standalone.xml中的整个jaxrs子系统,如jboss-deployment-structure.xml中除RESTEasy模块之外的其他帖子中所述也可以。

<jboss-deployment-structure xmlns="urn:jboss:deployment-structure:1.0">
  <deployment>
    <exclusions>
      <module name="org.jboss.resteasy.resteasy-atom-provider" />
      <module name="org.jboss.resteasy.resteasy-cdi" />
      <module name="org.jboss.resteasy.resteasy-jaxrs" />
      <module name="org.jboss.resteasy.resteasy-jaxb-provider" />
      <module name="org.jboss.resteasy.resteasy-jackson-provider" />
      <module name="org.jboss.resteasy.resteasy-jsapi" />
      <module name="org.jboss.resteasy.resteasy-multipart-provider" />
      <module name="org.jboss.resteasy.async-http-servlet-30" />
    </exclusions>
  </deployment>
</jboss-deployment-structure>

同时查看

答案 2 :(得分:6)

我认为正确的方法是使用与app server无关的JAX-RS应用程序部署。无需乱搞任何JBoss配置。您只需在JAX-RS Web应用程序中扩展javax.ws.rs.core.Application即可。您可以找到示例here。然后,您需要将它放在您的web.xml中。

<servlet>
  <servlet-name>Jersey Web Application</servlet-name>
  <servlet-class>com.sun.jersey.spi.container.servlet.ServletContainer</servlet-class>
  <init-param>
    <param-name>javax.ws.rs.Application</param-name>
    <param-value>jersey.MyApplication</param-value>
  </init-param>
  <context-param>
    <param-name>resteasy.scan</param-name>
    <param-value>false</param-value>
  </context-param>
  <context-param>
    <param-name>resteasy.scan.providers</param-name>
    <param-value>false</param-value>
  </context-param>
  <context-param>
    <param-name>resteasy.scan.resources</param-name>
    <param-value>false</param-value>
  </context-param>

  <load-on-startup>1</load-on-startup>
</servlet>

软件包扫描机制在JBoss 7.x上无法正常运行。我已经在JBoss 7.0.2.Final和JBoss 7.1.1.Final中成功测试了这种方法。

答案 3 :(得分:3)

 <jboss-deployment-structure xmlns="urn:jboss:deployment-structure:1.2">
  <deployment>
    <exclude-subsystems>
    <subsystem name="jaxrs" />
    </exclude-subsystems>
   </deployment>
 </jboss-deployment-structure>

会不会有诀窍,适用于7.3AS.ctomc,最后错过了一个小斜杠,以终止该部分。: - )

答案 4 :(得分:1)

我设法在我的JBOSS AS7上运行Jersey WS。

我为JBOSS做的只是删除与standalone.xml中的jax-rs相关的所有内容

我的球衣示例代码来自: http://www.ibm.com/developerworks/web/library/wa-aj-tomcat/

我为球衣做的唯一事情是从web.xml中删除init-param并将jersey lib复制到WebContent / WEB-INF / lib。

  <!--<init-param>
    <param-name>com.sun.jersey.config.property.packages</param-name>
    <param-value>sample.hello.resources</param-value>
  </init-param>-->

答案 5 :(得分:1)

In web.xml file add the files

        <context-param>
            <param-name>resteasy.scan</param-name>
            <param-value>false</param-value>
        </context-param>
        <context-param>
            <param-name>resteasy.scan.providers</param-name>
            <param-value>false</param-value>
        </context-param>
        <context-param>
            <param-name>resteasy.scan.resources</param-name>
            <param-value>false</param-value>
        </context-param>

 and comment out the init-param
        <!-- <init-param>
                  <param-name>com.sun.jersey.config.property.packages</param-name>
                  <param-value></param-value>
        </init-param> -->

This worked out for me in jboss-as-7.1.1.Final and i did not do any changes in standalone.xml.

答案 6 :(得分:1)

Ahother选项:

  1. 编辑standalone / configuration / standalone.xml并注释掉所有jaxrs条目。这将配置Jersey而不是RESTEasy。
  2. 从WEB-INF / web.xml中删除jboss-web.xml。这个文件没有longers适用于JBoss 7
  3. 编辑web.xml,添加一个配置到资源包中的init-param com.sun.jersey.config.property.packages,如:

    <init-param>
        <param-name>com.sun.jersey.config.property.packages</param-name>
        <param-value>org.foo</param-value>
    </init-param>
    
  4. https://github.com/Atmosphere/atmosphere/wiki/Deploying-Atmosphere-Jersey-in-JBoss-7.1.x

答案 7 :(得分:0)

您可以在独立配置中通过修改配置/ standalone.xml并删除扩展和配置文件部分中对jaxrs的引用来解决此问题。请注意,即使我在standalone.xml中对这些部分进行了评论,JBoss也会在下次启动时自动删除这些引用...

答案 8 :(得分:0)

我们能否更新“服务器不可知”方法以包含JBoss 7.1.1和Servlet 3.0?

<context-param>在3.0版web-xml中无效。

答案 9 :(得分:0)

以下是JBoss 7.1.1和Jersey 1.17.1对我有用的内容。无需修改standalone.xmldomain.xml。除了在web.xml中过滤restEasy,还要指示Jersey使用Jackson。您可以阅读有关此配置here的信息。

为了节省配置猜测的时间,我将从测试项目发布web.xmlpom.xml

<强>的web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0">
  <display-name>TestJerseyonJBoss</display-name>
  <servlet>
    <servlet-name>Jersey REST Service</servlet-name>
    <servlet-class>com.sun.jersey.spi.container.servlet.ServletContainer</servlet-class>
    <init-param>
      <param-name>com.sun.jersey.config.property.packages</param-name>
      <param-value>com.test.rest</param-value>
    </init-param>
    <init-param>
        <param-name>com.sun.jersey.api.json.POJOMappingFeature</param-name>
        <param-value>true</param-value>
    </init-param>
    <load-on-startup>1</load-on-startup>
  </servlet>
  <servlet-mapping>
    <servlet-name>Jersey REST Service</servlet-name>
    <url-pattern>/rest/*</url-pattern>
  </servlet-mapping>
   <context-param>
        <param-name>resteasy.scan</param-name>
        <param-value>false</param-value>
    </context-param>
    <context-param>
        <param-name>resteasy.scan.providers</param-name>
        <param-value>false</param-value>
    </context-param>
    <context-param>
        <param-name>resteasy.scan.resources</param-name>
        <param-value>false</param-value>
    </context-param>
</web-app>

<强>的pom.xml

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>TestJerseyOnJBoss</groupId>
  <artifactId>TestJerseyOnJBoss</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <packaging>war</packaging>
  <build>
    <sourceDirectory>src</sourceDirectory>
    <plugins>
      <plugin>
        <artifactId>maven-compiler-plugin</artifactId>
        <version>3.1</version>
        <configuration>
          <source>1.7</source>
          <target>1.7</target>
        </configuration>
      </plugin>
      <plugin>
        <artifactId>maven-war-plugin</artifactId>
        <version>2.3</version>
        <configuration>
          <warSourceDirectory>WebContent</warSourceDirectory>
          <failOnMissingWebXml>false</failOnMissingWebXml>
        </configuration>
      </plugin>
    </plugins>
  </build>
  <dependencies>
    <dependency>
        <groupId>com.sun.jersey</groupId>
        <artifactId>jersey-bundle</artifactId>
        <version>1.17.1</version>
    </dependency>

        <dependency>
           <groupId>com.sun.jersey</groupId>
           <artifactId>jersey-json</artifactId>
           <version>1.17.1</version>
        </dependency>
    <dependency>
               <groupId>asm</groupId>
               <artifactId>asm</artifactId>
               <version>3.3.1</version>
               <type>jar</type>
               <scope>compile</scope>
    </dependency>
  </dependencies>

答案 10 :(得分:0)

您应该排除jaxrs子系统被激活以进行部署 将其添加到META-INF / jboss-deployment-structure.xml

<jboss-deployment-structure xmlns="urn:jboss:deployment-structure:1.2">
  <deployment>
     <exclude-subsystems>
        <subsystem name="jaxrs" />
    </exclude-subsystems>
  <deployment>
 </jboss-deployment-structure>

或者您可以转到standalone.xml并删除子系统。 为此,您需要删除

<subsystem xmlns="urn:jboss:domain:jaxrs:1.0">
...
...
<subsystem>

配置的一部分,顶部的扩展部分可以保持它不会伤害任何方式。 或者您可以使用CLI连接到服务器并运行

/subsystem=webservices:remove()

只是注意,排除子系统功能和部署结构:在7.1.2中添加了1.2,因此在7.1.1上不起作用。