无法 运行 使用 Wildfly 网络服务器的 JaxRs 网络服务
Unable to run JaxRs web service using Wildfly web server
您好,我正在尝试在 JBoss developer studio 和 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 的新手,并且特别是网络服务,刚开始为一家使用 Jboss eap 服务器的公司工作,这与 wildfly 完全相同,不幸的是,我在处理网络服务任务时也收到了同样的错误。
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>
我的 java class 在包裹 com.test.jaxrs.service 中是
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;
}
}
请告诉我野蝇哪里出了问题....提前致谢
Wildfly 和 EAP 是完整的 JEE 服务器 - 无需在您的 pom.xml
中包含 Jersey 依赖项。 Tomcat 需要,因为它主要是一个 servlet/JSP 引擎。您的服务看起来不错,但您的 pom.xml
和 web.xml
是使用 Tomcat 的结果。此外,如果您不想要,则不再需要 web.xml
,当然也不需要使用 Jersey 来映射它。
您还需要一个文件 - Application
class 开始工作。它看起来像:
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
将创建一个 .war 文件,您可以将其部署到 Wildfly。这已经很简单了,现在请删除你的 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>
您好,我正在尝试在 JBoss developer studio 和 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 的新手,并且特别是网络服务,刚开始为一家使用 Jboss eap 服务器的公司工作,这与 wildfly 完全相同,不幸的是,我在处理网络服务任务时也收到了同样的错误。
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>
我的 java class 在包裹 com.test.jaxrs.service 中是
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;
}
}
请告诉我野蝇哪里出了问题....提前致谢
Wildfly 和 EAP 是完整的 JEE 服务器 - 无需在您的 pom.xml
中包含 Jersey 依赖项。 Tomcat 需要,因为它主要是一个 servlet/JSP 引擎。您的服务看起来不错,但您的 pom.xml
和 web.xml
是使用 Tomcat 的结果。此外,如果您不想要,则不再需要 web.xml
,当然也不需要使用 Jersey 来映射它。
您还需要一个文件 - Application
class 开始工作。它看起来像:
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
将创建一个 .war 文件,您可以将其部署到 Wildfly。这已经很简单了,现在请删除你的 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>