Java Jax rs资源404未找到错误
我在使用jax rs在java中运行应用程序时遇到以下错误Java Jax rs资源404未找到错误,java,maven,jax-rs,Java,Maven,Jax Rs,我在使用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 th
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>
我收到
404
错误。如何解决相同的问题我认为你的URL是http://localhost:8080/resources/greetUser.
如果需要,通常在应用服务器中配置带有artifactId部分的URL。您是如何部署代码的?因此您正在向Tomcat部署
.war
文件?文件名是什么?这并没有回答我的问题。构建时,结果是一个.war
文件,然后将其部署到Tomcate,对吗?您正在部署的文件的名称是什么?如果您检查Tomcat日志文件,Web应用程序启动时是否没有错误?因为您的pom.xml
文件没有显示任何Spring依赖项,为什么要标记Spring
和Spring boot
?尝试添加注释@GET@Path(“/”)公共字符串greetUser()你能在回答中写同样的内容吗?其实我没有understand@ShwetaMishra你好你们解决问题了吗?如果是-发布解决方案:-)
GET http://localhost:8080/ajavaeeconcurrency/resources/greetUser