java - Jax rs 资源 404 未找到错误
问题描述
使用 jax-rs 在 java 中运行应用程序时出现以下错误
HTTP Status 404 – Not Found
Type Status Report
Message /ajavaeeconcurrency/resources/greetUser
Description The origin server did not find a current representation for the target resource or is not willing to disclose that one exists.
Apache Tomcat/9.0.30
我正在使用 java8 并尝试使用 jax-rs 创建restAPI 下面是代码
package com.app.rest;
import javax.ws.rs.ApplicationPath;
import javax.ws.rs.core.Application;
@ApplicationPath("resources")
public class JAXRSConfiguration extends Application {
}
下面是资源类
package com.app.rest;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
@Path("/greetUser")
public class GreetResource {
@GET
public String greetUser()
{
return "java EE concurrency starts.";
}
这是我的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/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.mycompany</groupId>
<artifactId>ajavaeeconcurrency</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>war</packaging>
<dependencies>
<dependency>
<groupId>javax</groupId>
<artifactId>javaee-api</artifactId>
<version>8.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.eclipse.microprofile</groupId>
<artifactId>microprofile</artifactId>
<version>2.0.1</version>
<type>pom</type>
<scope>provided</scope>
</dependency>
</dependencies>
<build>
<finalName>ajavaeeconcurrency</finalName>
</build>
<properties>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<failOnMissingWebXml>false</failOnMissingWebXml>
</properties>
</project>
我artifactId
的是ajavaeeconcurrency
。我正在尝试使用以下访问资源URI
GET http://localhost:8080/ajavaeeconcurrency/resources/greetUser
我收到404
错误。我该如何解决相同的问题
解决方案
我认为您的 URL 是 http://localhost:8080/resources/greetUser。
如果需要,通常在应用程序服务器中配置带有 artifactId 部分的 URL。
推荐阅读
- python - 使用 Pyglet 设置窗口的分辨率并移动
- android - 关于在Android中保存和加载对象的问题
- r - 通过使用 dplyr 添加包含序列号的变量来扩展(爆炸?)data.frame
- python - Python:如何在 Python 中反序列化经过训练的 dlib 模型数据(.dat)?
- rxjs - RXJS 定时器在 takeWhile 运算符返回 'false' 后继续运行
- node.js - Google Action 可能存在的错误:SIGN_IN 后不显示列表小部件
- python - 如何防止 python 请求解码我的 URL
- web-crawler - 澄清 Stormcrawler 的 default-regex-filters.txt 是如何工作的
- amazon-web-services - NVidia 驱动程序停止在带有 Ubuntu 16.04 和 Tesla K80 GPU 的 AWS EC2 实例上工作
- python - Jython:NameError:未定义全局名称