无法在Tomcat 9上运行Jersey 2 Restful Web服务

姆索伊

我正在编写Jersey 2 Restful Web服务。这是服务类:

package com.Test.PS;
import java.io.IOException;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.QueryParam;
import javax.ws.rs.Consumes;
import javax.ws.rs.POST;

import com.Test.Exchange.*; // Here class UserInfo is defined

@Path("/ps")
public class TestService {
    private UserInfo ui;
    public TestService () throws IOException {
        ui = new UserInfo();
    }
    public TestService (String uid) throws IOException {
        UserInfo ui = ObjectFileStore.serializeDataIn(uid);
    }

    public TestService (UserInfo ui) throws IOException {
        this.ui = ui;
        ObjectFileStore.serializeDataOut(ui);
    }

    @GET
    @Produces(MediaType.TEXT_HTML)
    public String sayHelloHTML(@QueryParam("uid") String uid) {     
        String resource="<h1> Hi '" + uid + "'. </h1>";
        return resource;
    }

    @POST
    @Consumes(MediaType.APPLICATION_JSON)
    @Produces(MediaType.APPLICATION_JSON)
    public UserInfo postNK(@QueryParam("asid") String asid, UserInfo u) {
        return ui;
    }
}

这是Maven的依赖项:

<dependency>
  <groupId>org.glassfish.jersey.core</groupId>
  <artifactId>jersey-server</artifactId>
  <version>2.27</version>
  <scope>provided</scope>
</dependency>

<dependency>
  <groupId>org.glassfish.jersey.core</groupId>
  <artifactId>jersey-client</artifactId>
  <version>2.27</version>
  <scope>provided</scope>
</dependency>

<dependency>
  <groupId>org.glassfish.jersey.containers</groupId>
  <artifactId>jersey-container-servlet</artifactId>
  <version>2.27</version>
  <scope>provided</scope>
</dependency>

<dependency>
  <groupId>javax.servlet</groupId>
  <artifactId>javax.servlet-api</artifactId>
  <version>4.0.1</version>
  <scope>provided</scope>
</dependency>

<dependency>
  <groupId>org.glassfish.jersey.inject</groupId>
  <artifactId>jersey-hk2</artifactId>
  <version>2.27</version>
  <scope>provided</scope>
</dependency>

最后,这是我的web.xml文件:

  <display-name>Test-PS</display-name>
  <welcome-file-list>
    <welcome-file>index.html</welcome-file>
  </welcome-file-list>

  <servlet>
    <servlet-name>Test-PS</servlet-name>
    <servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class>

    <init-param>
      <param-name>jersey.config.server.provider.packages</param-name>
      <param-value>com.Test.PS</param-value>
    </init-param>

    <load-on-startup>1</load-on-startup>
  </servlet>

  <servlet-mapping>
    <servlet-name>Test-PS</servlet-name>
    <url-pattern>/rest/*</url-pattern>
  </servlet-mapping>
</web-app>

使用url(http:// localhost:8081 / Test-PS / rest / ps?uid = 90在Tomcat 9上运行此服务时出现以下错误

HTTP Status 404 – Not Found
Type Status Report
Message /Test-PS/rest/ps
Description The origin server did not find a current representation for the target resource or is not willing to disclose that one exists.

在控制台屏幕上,我看到:

INFO: Reloading Context with name [/Test-PS] has started
org.apache.jasper.servlet.TldScanner scanJars
INFO: At least one JAR was scanned for TLDs yet contained no TLDs. Enable debug logging for this logger for a complete list of JARs that were scanned but no TLDs were found in them. Skipping unneeded JARs during scanning can improve startup time and JSP compilation time.
org.apache.catalina.core.StandardContext reload
INFO: Reloading Context with name [/Test-PS] is completed

我尝试添加其他依赖项,如此处其他帖子所建议的那样,但是仍然存在相同的问题。令人惊讶的是,有时它会以未知的原因起作用!!!

我还删除了所有的Maven存储库,没有任何更改!!!

姆索伊

该问题通过以下方式解决:

  • 删除Eclipse并安装EE版本。
  • 删除Tomcat并安装9.0.11版本。
  • 从头开始创建项目。

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

无法将JSON数据发布到Jersey Restful Web服务

在 Tomcat 上使用 Spark Web 框架的 RESTful 服务

如何在Glassfish 4上创建一个简单的JSON Jersey 2.x RESTful Web服务?

通过TomEE使用Jersey RESTful Web服务

如何运行Spring RESTful Web服务

使用Ear / EJB / Web模块时,Glassfish 4.1无法运行RestFul服务

创建和GlassFish上运行RESTful Web服务

无法在IntelliJ Idea 2017.3.4上使用Maven创建RESTful Web服务

Java Web 应用程序无法在使用 Jersey 2.26 的 Tomcat 8.5 或 9 上启动

使用Jersey +休眠RESTful Web服务上传和下载图像

Jersey RESTful Web 服务 - 使用多个对象上传文件

从Jersey RESTful Web服务中抛出提示性错误消息

在AngularJS 2中对RESTful Web服务进行身份验证

具有多个参数的RESTful Struts2 Web服务

使用Jersey在Java中运行简单的RESTful Web服务时的HTTP状态404

使用码头9运行jersey 2服务器

Java Restful Web服务,无法确定如何执行特定的查询

为什么无法获得RESTful Web服务响应?GET方法

在java中运行Restful Web服务时出现404错误

无法在Apache Tomcat上运行JAX-WS Java Web服务

ColdFusion RESTful Web 服务

RESTFUL Web 服务 - 列表

关于RESTful Web服务

RESTful Web服务端点上的JAX-WS @WebService

在Android Studio上测试RESTful Web服务(RESTClient)

RESTful Web服务上的Apache HTTP请求异常结束

无法从AngularJS调用RESTFul服务

无法在Pivotal Web服务上运行

运行jersey 2 Web服务时我缺少什么?