泽西岛:请求资源不可用 [英] Jersey: The request resource is not available

查看:132
本文介绍了泽西岛:请求资源不可用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图使我的第一个Jersey Web服务项目正常工作,但出现此错误Jersey: The requested resource is not available.我已经通过eclispe Maven安装了Jersey 2.16并安装了Tomcat 8.0.21我在

I am trying to get my first Jersey web service project to work but I am getting this error Jersey: The requested resource is not available. I have installed Jersey 2.16 by eclispe Maven and installed Tomcat 8.0.21 I have craeted the MessageResource.java class inside scr/main/java - org.test.messanger

我正在输入此链接:

http://localhost:8080/messanger/webapi/messages

如果我点击此链接http://localhost:8080/messanger/webapi/myresource,我会得到Got it!

If I klick this link http://localhost:8080/messanger/webapi/myresource I am getting Got it!

我用以下数据向Jersy和maven添加了

I added Jersy with maven with this data:

  • org.glassfish.jersey.archetypes
  • jersey-Quickstart-webapp
  • 2.16

MessageResource.java

MessageResource.java

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


@Path("/messages")
public class MessageResource {

    @GET
    @Produces(MediaType.TEXT_PLAIN)
    public String getMessages(){
        return "Hello world";
    }

}

工作代码:

package org.test.messanger;

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

/**
 * Root resource (exposed at "myresource" path)
 */
@Path("myresource")
public class MyResource {

    /**
     * Method handling HTTP GET requests. The returned object will be sent
     * to the client as "text/plain" media type.
     *
     * @return String that will be returned as a text/plain response.
     */
    @GET
    @Produces(MediaType.TEXT_PLAIN)
    public String getIt() {
        return "Got it!";
    }
}

web.xml

<?xml version="1.0" encoding="UTF-8"?>
<!-- This web.xml file is not required when using Servlet 3.0 container,
     see implementation details http://jersey.java.net/nonav/documentation/latest/jax-rs.html -->
<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
    <servlet>
        <servlet-name>Jersey Web Application</servlet-name>
        <servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class>
        <init-param>
            <param-name>jersey.config.server.provider.packages</param-name>
            <param-value>org.test.messanger</param-value>
        </init-param>
        <load-on-startup>1</load-on-startup>
    </servlet>
    <servlet-mapping>
        <servlet-name>Jersey Web Application</servlet-name>
        <url-pattern>/webapi/*</url-pattern>
    </servlet-mapping>
</web-app>

推荐答案

我遇到了同样的问题.我的问题是我没有构建eclipse项目,而是直接尝试在服务器上运行它.

I faced the same issue. The problem with me was that I didn't build my eclipse project and was directly trying to run it on the server.

  • 右键单击您的项目
  • 点击Build Project
  • 项目一旦建立,就可以在服务器上运行.

这篇关于泽西岛:请求资源不可用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆