使用resteasy-jaxrs 的简单示例不起作用

2023-12-31

当我访问该页面时,我无法收到“hello”消息。

package jaxrs.ressources;

import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;

@Path("greeting")
public class HelloRessource {
    @GET
    @Path("hello")
    @Produces(MediaType.TEXT_PLAIN)
    public String sayhello() {
    return "Hello from JAX-RS";
}}

和这个班级

package jaxrs.utilities;

import javax.ws.rs.ApplicationPath;
import javax.ws.rs.core.Application;

@ApplicationPath("/rest")
public class RestActivator  extends Application{

}

The url http://127.0.0.1:8383/JAXRS_Hello_GL-1.0/rest/greeting/hello总是显示“未找到”

有什么解决办法吗?

这是包含 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.esprit.jaxrs.hello</groupId>
  <artifactId>JAXRS_Hello_GL</artifactId>
  <version>1.0</version>
  <packaging>war</packaging>

  <properties>
    <failOnMissingWebXml>false</failOnMissingWebXml>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <maven.compiler.target>1.8</maven.compiler.target>
    <maven.compiler.source>1.8</maven.compiler.source>
  </properties>
  <!-- https://mvnrepository.com/artifact/org.jboss.resteasy/resteasy-jaxrs -->
<dependencies>

<!-- https://mvnrepository.com/artifact/org.jboss.resteasy/resteasy-jaxrs -->
<dependency>
    <groupId>org.jboss.resteasy</groupId>
    <artifactId>resteasy-jaxrs</artifactId>
    <version>3.1.4.Final</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.jboss.resteasy/resteasy-jaxrs -->
<dependency>
    <groupId>org.jboss.resteasy</groupId>
    <artifactId>resteasy-client</artifactId>
    <version>3.1.4.Final</version>
</dependency>

  </dependencies>

</project>

如果您需要其他说明,请告诉我


您可以添加初始化程序吗:

<dependency>
    <groupId>org.jboss.resteasy</groupId>
    <artifactId>resteasy-servlet-initializer</artifactId>
    <version>3.1.4.Final</version>
</dependency>

Paul先生在评论中有解决方案,请查看

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

使用resteasy-jaxrs 的简单示例不起作用 的相关文章

随机推荐