gpt4 book ai didi

Tomcat错误404 : The origin server did not find a current representation for the target resource or is not willing to disclose that one exists

转载 作者:行者123 更新时间:2023-11-28 23:10:30 24 4
gpt4 key购买 nike

我正在尝试使用 apache Tomcat 部署一个简单的 Jax-RS 应用程序。服务器在我的本地主机上正常运行,tomcat 主页已启动。但是当我从我的服务器上的 eclipse 运行时,我收到状态 404 错误。有谁知道这是为什么吗?

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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.javaee8</groupId>
<artifactId>hello-javaee8</artifactId>
<packaging>war</packaging>
<version>0.0.1-SNAPSHOT</version>
<name>hello-javaee8 Maven Webapp</name>
<url>http://maven.apache.org</url>


<dependencies>
<dependency>
<groupId>javax</groupId>
<artifactId>javaee-api</artifactId>
<version>8.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<version>2.5</version>
</dependency>

</dependencies>
<build>
<finalName>hello-javaee8</finalName>
</build>
</project>

Web.xml


<!DOCTYPE web-app PUBLIC
"-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
"http://java.sun.com/dtd/web-app_2_3.dtd" >

<web-app>
<display-name>Archetype Created Web Application</display-name>
</web-app>

如果我需要添加任何其他文件来找到这个解决方案,请告诉我

最佳答案

有两个原因。

首先,您不包括 JAX-RS 实现,仅包括 JAX-RS API。 JAX-RS API 仅提供一组接口(interface),并由实现来提供这些接口(interface)的具体实现。

如果您没有 JAX-RS 实现,我建议您使用 Jersey(引用实现)。将以下内容添加到您的 pom.xml:

<dependency>
<groupId>org.glassfish.jersey.containers</groupId>
<artifactId>jersey-container-servlet-core</artifactId>
<version>2.29</version>
</dependency>

其次,您尚未在 web.xml 中的任何位置注册您的应用程序。如何执行此操作取决于您使用的 JAX-RS 实现以及您如何注册您的类和提供者。为了帮助您解决这个问题,我需要您回答几个问题:

  1. 您是否有实现 Application 的类(或扩展 ResourceConfig 的类)?
  2. 是否所有的资源类都用 @Path 注释并且所有的提供者都用 @Provider 注释?
  3. 您所有的资源类和提供者都在同一个包中吗?
  4. 您要使用哪种 JAX-RS 实现?

如果您使用 Jersey 并对第一个问题回答是,请将以下内容放入 web.xml:

<servlet>
<servlet-name>Jersey Web Application</filter-name>
<servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class>
<init-param>
<param-name>javax.ws.rs.Application</param-name>
<param-value><!-- FQN of your Application/ResourceConfig class --></param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>Jersey Web Application</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>

否则,请查看特定 JAX-RS 框架的设置说明。

关于Tomcat错误404 : The origin server did not find a current representation for the target resource or is not willing to disclose that one exists,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58660821/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com