当前位置: 首页 > 知识库问答 >
问题:

无法使用Wildfly web服务器运行JaxRs web服务

邵博远
2023-03-14

您好,我正试图在JBoss developer studio和Wildfly 11上构建一个简单的JaxRs web服务作为应用程序服务器,但我在尝试部署maven项目时遇到以下错误:

无法启动服务jboss。下拖。部署。默认服务器。默认主机。“/JaxRsTest-0.0.1-SNAPSHOT”:org。jboss。理学硕士。服务服务jboss中的StartException。下拖。部署。默认服务器。默认主机。“/JaxRsTest-0.0.1-SNAPSHOT”:java。lang.NoSuchMethodError:org。阿帕奇。公猫util。描述符。消化工厂。newDigester(ZZLorg/apache/tomcat/util/digester/RuleSet;Z)Lorg/apache/tomcat/util/digester/digester

另外,我想通知你,当我使用apache tomcat 9时,该项目运行良好,但是当我切换到Wildfly 11时,它会抛出上述错误。我是java和特别Web服务的新手,刚刚开始为一家使用与Wildfly完全相同的Jboss eap服务器的公司工作,不幸的是,我在处理Web服务分配时也收到了同样的错误。

For more reference below is my pom.xml file :

    <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>JaxRsServiceTest</groupId>
      <artifactId>JaxRsServiceTest</artifactId>
      <version>0.0.1-SNAPSHOT</version>
      <packaging>war</packaging>
      <dependencies>
            <dependency>
                <groupId>com.sun.jersey</groupId>
                <artifactId>jersey-server</artifactId>
                <version>1.19</version>
            </dependency>
            <dependency>
                <groupId>com.sun.jersey</groupId>
                <artifactId>jersey-servlet</artifactId>
                <version>1.19</version>
            </dependency>
        </dependencies>
      <build>
        <sourceDirectory>src</sourceDirectory>
        <plugins>
          <plugin>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.5.1</version>
            <configuration>
              <source>1.8</source>
              <target>1.8</target>
            </configuration>
          </plugin>
          <plugin>
            <artifactId>maven-war-plugin</artifactId>
            <version>3.0.0</version>
            <configuration>
              <warSourceDirectory>WebContent</warSourceDirectory>
            </configuration>
          </plugin>
        </plugins>
      </build>
    </project>

和我的网络。xml文件内容为:

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" id="WebApp_ID" version="3.1">
  <display-name>JaxRsServiceTest</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.jaxrs.service</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>
</web-app>

还有com包中的java类。测验jaxrs。服务是

  package com.test.jaxrs.service;

import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;

@Path("/test")
public class JaxRsTest {

    @GET
    @Path("/hello/{msg}")
    @Produces(MediaType.TEXT_PLAIN)
    public String processRequest(@PathParam(value="msg")String message)
    {
        return "Hello : " + message;
    }
}

请让我知道我在野蝇方面出了什么问题。。。。提前谢谢你


共有1个答案

锺离明煦
2023-03-14

Wildfly和EAP是一个完整的JEE服务器——没有必要在您的pom.xml中包含泽西依赖项。Tomcat需要这样做,因为它主要是一个servlet/JSP引擎。您的服务看起来不错,但是您的pom.xmlweb.xml是使用Tomcat的结果。此外,如果您不想要,您不再需要web.xml,并且您当然不需要使用泽西来映射它。

您还需要一个文件,即启动应用程序的类。它看起来像:

import javax.ws.rs.ApplicationPath;
import javax.ws.rs.core.Application;

/**
 * Used to bootstrap JAX-RS.  Otherwise this class is
 * not directly used.
 */
@ApplicationPath("/rest")
public class RestApplicationConfig extends Application {
    // intentionally empty
}

它可以在源代码树中的任何位置。请注意,它接管了/rest路径,该路径类似于您在web.xml中的路径。

pom。下面的xml将创建一个。可以部署到Wildfly的war文件。这很简单,再次删除您的web。xml(目前)。

pom。xml

<?xml version="1.0" encoding="UTF-8"?>
<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/maven-v4_0_0.xsd">

    <modelVersion>4.0.0</modelVersion>
    <groupId>JaxRsServiceTest</groupId>
    <artifactId>JaxRsServiceTest</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>war</packaging>

    <properties>
        <maven.compiler.source>1.8</maven.compiler.source>
        <maven.compiler.target>1.8</maven.compiler.target>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <failOnMissingWebXml>false</failOnMissingWebXml>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.jboss.resteasy</groupId>
            <artifactId>jaxrs-api</artifactId>
            <version>3.0.12.Final</version>
            <scope>provided</scope>
        </dependency>
    </dependencies>
</project>

 类似资料:
  • 我可以在我自己的电脑上使用这个程序,但是我不能在服务器上使用。 服务器使用最高权限管理员打开程序。 具有的服务器WCF HTTP激活功能。NET4。5号门开着。 服务器endpoint地址使用"http://localhost",如下所示 endpoint地址="http://localhost"绑定="basicHttpBind"bindingConfiguration="NewBinding0

  • ~/tests>uname-a Linux ghopper-K52F 4.10.0-40-generic#44-Ubuntu SMP Thu 11月9日14:49:09 UTC 2017 x86_64 x86_64 x86_64 gnu/Linux 我想用chromedriver启动服务器 null 附言。我在另一台电脑上做同样的事情,对我来说一切都很好。我认为问题出在环境上,而不是服务器的配置上

  • 我正在开发一个android和iOS应用程序,需要有一个RESTful服务器端。直到今天,我在eclipse上使用Jersey和RunJettyRun,但我决定开始使用新的更好的东西!我搬到了DropWizard和IntelliJ IDEA 这些是我安装的软件和我已经处理的事情:-Java 8-Maven 3.1.1-Maven和Java的环境变量。 现在,我所做的是跟随他们网站上的DropWiz

  • 我使用服务总线触发器创建了一个azure函数,当我尝试运行该函数时,我得到了这个错误: 我为开发存储设置了local.settings.json文件 我在使用AzureWebJobsStorage的函数中有连接字符串 我不知道是什么问题。如果有任何帮助,将不胜感激。

  • 我一直在寻找一个解决办法,但没有找到一个有效的解决办法。 我已经在我的MacBook中使用brew安装了postgres(),并且我目前正在使用brew服务运行它(将postgres显示为正在运行的服务)。但是,当我尝试运行时,我得到以下错误。 PSQL:无法连接到服务器:没有这样的文件或目录是本地运行并接受Unix域套接字“/tmp/.s.pgsql.5432”上的连接的服务器吗? 有人已经解决

  • 问题内容: 当我尝试检入机器B时,我正在从机器A运行python manage.py runserver。我键入的URL是http:// A:8000 / 我收到类似系统返回的错误:(111)连接被拒绝 问题答案: 你可以通过以下方式为网络中的计算机运行它 这样一来,你就可以从网络中的任何计算机访问服务器。只需在浏览器中的其他机器上键入你服务器的IP地址…就可以开始使用…了。 或者在你的情况下: