英文:
Jax rs resources 404 not found errror
问题
我在使用Java的jax-rs运行应用程序时遇到以下错误:
HTTP状态404 - 未找到
类型状态报告
消息 /ajavaeeconcurrency/resources/greetUser
描述 原始服务器未找到目标资源的当前表示,或不愿透露该资源的存在。
Apache Tomcat/9.0.30
我正在使用Java 8,尝试使用jax-rs创建REST API。
以下是代码:
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 错误。我应该如何解决这个问题?
英文:
I am getting below error while running application in java using jax-rs
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
I am using java8 and trying to create restAPI using jax-rs
Below is the code
package com.app.rest;
import javax.ws.rs.ApplicationPath;
import javax.ws.rs.core.Application;
@ApplicationPath("resources")
public class JAXRSConfiguration extends Application {
}
Below is resource class
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.";
	}
This is my 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>
My artifactId is ajavaeeconcurrency . I am trying to access resource using below URI
GET http://localhost:8080/ajavaeeconcurrency/resources/greetUser
I am getting 404 error. How can I resolve the same
答案1
得分: 1
我认为你的URL是http://localhost:8080/resources/greetUser。
URL中的artifactId部分通常在应用服务器中配置,如果有需要的话。
英文:
I think your URL is http://localhost:8080/resources/greetUser.
URL with artifactId part usually configuried in application server if it need.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。


评论