Jax rs资源未找到错误404。

huangapple go评论73阅读模式
英文:

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>

我的 artifactIdajavaeeconcurrency。我尝试使用以下 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(&quot;resources&quot;)

public class JAXRSConfiguration extends Application {

}

Below is resource class

package com.app.rest;

import javax.ws.rs.GET;
import javax.ws.rs.Path;

@Path(&quot;/greetUser&quot;)
public class GreetResource {
	
	@GET
	public String greetUser()
	{
		return &quot;java EE concurrency starts.&quot;;
	}

This is my pom.xml

&lt;project xmlns=&quot;http://maven.apache.org/POM/4.0.0&quot;
	xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot;
	xsi:schemaLocation=&quot;http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd&quot;&gt;
	&lt;modelVersion&gt;4.0.0&lt;/modelVersion&gt;
	&lt;groupId&gt;com.mycompany&lt;/groupId&gt;
	&lt;artifactId&gt;ajavaeeconcurrency&lt;/artifactId&gt;
	&lt;version&gt;0.0.1-SNAPSHOT&lt;/version&gt;
	&lt;packaging&gt;war&lt;/packaging&gt;
	&lt;dependencies&gt;
		&lt;dependency&gt;
			&lt;groupId&gt;javax&lt;/groupId&gt;
			&lt;artifactId&gt;javaee-api&lt;/artifactId&gt;
			&lt;version&gt;8.0&lt;/version&gt;
			&lt;scope&gt;provided&lt;/scope&gt;
		&lt;/dependency&gt;

		&lt;dependency&gt;
			&lt;groupId&gt;org.eclipse.microprofile&lt;/groupId&gt;
			&lt;artifactId&gt;microprofile&lt;/artifactId&gt;
			&lt;version&gt;2.0.1&lt;/version&gt;
			&lt;type&gt;pom&lt;/type&gt;
			&lt;scope&gt;provided&lt;/scope&gt;
		&lt;/dependency&gt;
	&lt;/dependencies&gt;
	
	&lt;build&gt;
		&lt;finalName&gt;ajavaeeconcurrency&lt;/finalName&gt;
	&lt;/build&gt;
	
	&lt;properties&gt;
	
		&lt;maven.compiler.source&gt;1.8&lt;/maven.compiler.source&gt;
		&lt;maven.compiler.target&gt;1.8&lt;/maven.compiler.target&gt;
		&lt;failOnMissingWebXml&gt;false&lt;/failOnMissingWebXml&gt;
	&lt;/properties&gt;
&lt;/project&gt;

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.

huangapple
  • 本文由 发表于 2020年7月24日 19:08:45
  • 转载请务必保留本文链接:https://go.coder-hub.com/63072351.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定