在 Jboss AS 7 上部署 Jersey Web 应用程序

发布于 2024-11-28 13:38:32 字数 616 浏览 3 评论 0 原文

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

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

我已经做了一些搜索,发现 RestEasy 是嵌入的默认 JAX-RS 实现进入应用程序服务器。诸如 http://community.jboss.org/message/579996https://issues.jboss.org/browse/JBAS-8830)提到 RestEasy 部署程序接管。

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

Currently running some webapps on Jboss AS 4/5 and I am testing migration to jboss7. When I try to deploy a jersey based webapp on JBoss AS 7 (full profile with standalone-preview config file), I get:

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

I've done a bit of hunting around on it and found that RestEasy is the default JAX-RS implementation embedded into Application Server. Posts like http://community.jboss.org/message/579996 and https://issues.jboss.org/browse/JBAS-8830) mention that the RestEasy deployer takes over.

In AS 6, it seems easier to remove the deployer whereas I have not seen any solutions for AS 7.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(10

〆一缕阳光ご 2024-12-05 13:38:32

这篇文章已经提到过:https://community.jboss.org/message/744530# 744530 ,您可以要求 Resteasy 模块不要扫描您的 Web 应用程序中的其他 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>

对我来说效果很好

it has already been mentioned in this post : https://community.jboss.org/message/744530#744530 , you can just ask the resteasy module to not scan for other JAX RS implementations in your webapp; just add this to your 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>

worked fine for me

遗失的美好 2024-12-05 13:38:32

除了在其他帖子中提到的删除standalone.xml中的整个jaxrs子系统之外,排除jboss-deployment-struction.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>

另请查看

Besides removing the entire jaxrs subsystem in standalone.xml as mentioned in the other posts excluding the RESTEasy modules in jboss-deployment-structure.xml may also work.

<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>

Also check out

硪扪都還晓 2024-12-05 13:38:32

我认为正确的方法是使用与应用程序服务器无关的 JAX-RS 应用程序部署。无需搞乱任何 JBoss 配置。您所需要的只是扩展 javax.ws JAX-RS Web 应用程序中的 .rs.core.Application 。您可以在此处找到示例。然后,您需要将其放入 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 上无法正常工作。我已经在 J​​Boss 7.0.2.Final 和 JBoss 7.1.1.Final 中成功测试了这种方法。

I believe the correct approach is to use app server agnostic JAX-RS application deployment. No need to mess with any JBoss configuration. All you need is, extend javax.ws.rs.core.Application in your JAX-RS web application. You can find an example here. Then, you need to put this in your 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>

Package scanning mechanism does not work correctly on JBoss 7.x. I have tested this approach successfully in JBoss 7.0.2.Final and JBoss 7.1.1.Final.

你怎么敢 2024-12-05 13:38:32
 <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 只是在最后错过了一个小斜杠来终止该部分。:-)

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

Will do the trick, works great with 7.3AS.ctomc just missed a tiny slash in the end to terminate the section.:-)

帅冕 2024-12-05 13:38:32

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

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

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

我对球衣所做的唯一一件事就是从 web.xml 中删除 init-param 并将球衣 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>-->

I managed to run Jersey WS on my JBOSS AS7.

What i do for JBOSS is just remove everything related to jax-rs in standalone.xml

My jersey sample code got from:
http://www.ibm.com/developerworks/web/library/wa-aj-tomcat/

The only thing i do for the jersey is remove the init-param from web.xml and copy jersey lib to 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>-->
何以笙箫默 2024-12-05 13:38:32
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.
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.
萌梦深 2024-12-05 13:38:32

另一个选项:

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

    ;
        <参数名称>com.sun.jersey.config.property.packages
        <参数值>org.foo
    
    

https://github.com/Atmosphere/atmosphere/wiki/Deploying-Atmosphere-Jersey-in-JBoss-7.1.x

Ahother option:

  1. Edit standalone/configuration/standalone.xml and comments out all jaxrs entries. This will configure Jersey instead of RESTEasy.
  2. Remove jboss-web.xml from WEB-INF/web.xml. This file no longers works with JBoss 7
  3. Edit web.xml, add an init-param com.sun.jersey.config.property.packages configured to your resource's package, like:

    <init-param>
        <param-name>com.sun.jersey.config.property.packages</param-name>
        <param-value>org.foo</param-value>
    </init-param>
    

https://github.com/Atmosphere/atmosphere/wiki/Deploying-Atmosphere-Jersey-in-JBoss-7.1.x

↙温凉少女 2024-12-05 13:38:32

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

You can get past this in the standalone configuration by modifying configuration/standalone.xml and removing references to jaxrs in the extensions and profile section. Note, even though I commented those portions out in my standalone.xml, JBoss will automagically remove those references altogether on next startup...

岁吢 2024-12-05 13:38:32

这是对我来说适用于 JBoss 7.1.1 和 Jersey 1.17.1 的方法。无需修改 standalone.xmldomain.xml。除了在 web.xml 中过滤restEasy 之外,还指示 Jersey 使用 Jackson。您可以在此处了解此配置。

为了节省配置猜测的时间,我发布了测试项目中的 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>

Here is what worked for me for JBoss 7.1.1 and Jersey 1.17.1. No need to modify standalone.xml or domain.xml. Besides filtering restEasy in web.xml instruct Jersey to use Jackson. You can read about this configuration here.

To save time in configuration guesses, I am posting web.xml and pom.xml from test project.

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>

送你一个梦 2024-12-05 13:38:32

您应该排除 jaxrs 子系统在您的部署中被激活
将其添加到 META-INF/jboss-deployment-struct.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()

请注意,排除子系统功能和部署结构:1.2 已在 7.1.2 中添加,因此不适用于 7.1.1。

You should exclude jaxrs subsystem from being activated for your deployment
add this into 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>

or you can go to standalone.xml and remove subsystem there.
To do so, you need to remove

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

part of configuration, extension part of on top can stay it wont hurt either way.
or you can connect to server with CLI and run

/subsystem=webservices:remove()

Just a note, exclude-subsystems functionality and deployment-strucure:1.2 was added in 7.1.2 and as such will not work on on 7.1.1.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文