gpt4 book ai didi

Java Jersey 找不到资源

转载 作者:行者123 更新时间:2023-11-28 22:51:41 25 4
gpt4 key购买 nike

我已经创建了一个 jersey web 服务并将其部署在一个 tomcat 应用程序服务器上。我在 tomcat 中部署了 war 文件,但是当我尝试访问该应用程序时仍然出现错误,指出无法找到请求的数据(标准 tomcat 404 错误)。这是我的 web.xml 文件。

<?xml version="1.0" encoding="UTF-8"?>

http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID"version="2.5"> Jersey 索引.html

<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>sample.jsonStrip.resources</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>

<servlet-mapping>
<servlet-name>RestServlet</servlet-name>
<url-pattern>/rest/*</url-pattern>
</servlet-mapping>

这是我的 pom.xml

http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 org.rares.urs 网站 Jersey 0.0.1-快照 配料

<repositories>
<repository>
<id>maven2-repository.java.net</id>
<name>Java.net Repository for Maven</name>
<url>http://download.java.net/maven/2/</url>
<layout>default</layout>
</repository>
</repositories>
<packaging>war</packaging>

<build>
<finalName>JsonStrip</finalName>

<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.4</version>
<configuration>
<warSourceDirectory>WebContent</warSourceDirectory>
<failOnMissingWebXml>false</failOnMissingWebXml>
</configuration>
</plugin>

<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>tomcat-maven-plugin</artifactId>
<configuration>
<url>http://127.0.0.1:8888/manager</url>
<server>mytomcat</server>
<path>/Jersey</path>
</configuration>
</plugin>


<plugin>
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat8-maven-plugin</artifactId>
<version>2.2</version>
<configuration>
<url>http://127.0.0.1:8888/manager</url>
<server>TomcatServer</server>
<path>/Switch</path>
</configuration>
</plugin>

</plugins>
</build>

<dependencies>
<dependency>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>3.0.0</version>
</dependency>
<dependency>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.9</version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<version>2.5</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.jaxrs</groupId>
<artifactId>jackson-jaxrs-json-provider</artifactId>
<version>2.7.0</version>
</dependency>
<dependency>
<groupId>javax.ws.rs</groupId>
<artifactId>javax.ws.rs-api</artifactId>
<version>2.0.1</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.6</version>
</dependency>
<dependency>
<groupId>org.codehaus.jackson</groupId>
<artifactId>jackson-mapper-asl</artifactId>
<version>1.9.2</version>
</dependency>
<dependency>
<groupId>org.codehaus.jackson</groupId>
<artifactId>jackson-core-asl</artifactId>
<version>1.9.2</version>
</dependency>
<dependency>
<groupId>com.sun.jersey</groupId>
<artifactId>jersey-client</artifactId>
<version>1.8</version>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.core</groupId>
<artifactId>jersey-common</artifactId>
<version>2.22.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>asm</groupId>
<artifactId>asm</artifactId>
<version>3.3.1</version>
</dependency>
<dependency>
<groupId>com.sun.jersey</groupId>
<artifactId>jersey-bundle</artifactId>
<version>1.19</version>
</dependency>
<dependency>
<groupId>org.json</groupId>
<artifactId>json</artifactId>
<version>20140107</version>
</dependency>
<dependency>
<groupId>com.sun.jersey</groupId>
<artifactId>jersey-server</artifactId>
<version>1.19</version>
</dependency>
</dependencies>

这两个 xml 文件都位于 Jersey 根文件夹中。我见过 wab.xml 位于 WebContent/WEB-INF/web.xml 中的一些情况?我应该把它放在哪里?

谢谢!

最佳答案

<servlet-name>在 web.xml 中需要在两个位置匹配

<servlet-mapping> , <servlet-name>通过查找 <servlet> 告诉容器这个映射应该应用到哪个 servlet与相同<servlet-name> .现在您的 Jersey servlet 没有 URL 映射,因此它不会处理任何请求。

I have seen some cases when wab.xml is situated in WebContent/WEB-INF/web.xml? Where should I place it?

那里。我有一段时间没有使用 eclipse,但我很确定 WebContent 文件夹不是“真正的”文件夹。它只是一个 IDE 显示文件夹。它应该在真实的目录结构中映射到 src/main/webapp在 Maven 应用程序中。这就是 web.xml 应该是 src/main/webapp/WEB-INF 的地方

关于Java Jersey 找不到资源,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38052042/

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