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

时间:2018-01-17 19:52:47

标签: java jax-rs wildfly

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

  

Failed to start service jboss.undertow.deployment.default-server.default-host."/JaxRsTest-0.0.1-SNAPSHOT": org.jboss.msc.service.StartException in service jboss.undertow.deployment.default-server.default-host."/JaxRsTest-0.0.1-SNAPSHOT": java.lang.NoSuchMethodError: org.apache.tomcat.util.descriptor.DigesterFactory.newDigester(ZZLorg/apache/tomcat/util/digester/RuleSet;Z)Lorg/apache/tomcat/util/digester/Digester;

另外我想通知你,当我使用apache tomcat 9时项目工作正常但是当我切换到wildfly 11时它抛出了上面提到的错误。我是java和特殊Web服务的新手,刚开始为公司工作它使用的是与Wildfly完全相同的Jboss eap服务器,不幸的是我在网络服务分配时也收到同样的错误。

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>

我的web.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.test.jaxrs.service包中的java类是

  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 个答案:

答案 0 :(得分:0)

Wildfly和EAP是完整的JEE服务器 - 您的pom.xml中不需要包含Jersey依赖项。 Tomcat需要它,因为它主要是一个servlet / JSP引擎。您的服务看起来不错,但pom.xmlweb.xml是使用Tomcat的结果。此外,如果您不想要,则不再需要web.xml,而且您当然也不需要使用Jersey来映射它。

您还需要一个文件 - Application类可以启动。它看起来像:

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>
相关问题