简体   繁体   English

404错误:资源不可用泽西tomcat

[英]404 error: Resource not available jersey tomcat

I am trying to implement simple "Hello Jersey" program. 我正在尝试实现简单的“ Hello Jersey”程序。 But its giving me 但是它给了我

404 error: Resource not available 404错误:资源不可用

web.xml: web.xml:

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" id="WebApp_ID" version="3.1">
 <display-name>MessageProcessorMyTest</display-name>
 <welcome-file-list>
 <welcome-file>index.html</welcome-file>
 <welcome-file>index.htm</welcome-file>
 <welcome-file>index.jsp</welcome-file>
 <welcome-file>default.html</welcome-file>
 <welcome-file>default.htm</welcome-file>
 <welcome-file>default.jsp</welcome-file>
</welcome-file-list>
<servlet>
<servlet-name>Jersey MessageProcessor 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>com.example.wordcount</param-value>
</init-param>
<init-param>
 <param-name>unit:WidgetPU</param-name>
 <param-value>persistence/widget</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Jersey MessageProcessor Application</servlet-name>
<url-pattern>/rest/*</url-pattern>
</servlet-mapping>
</web-app>

MessageEnd.java: MessageEnd.java:

package com.example.wordcount;

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


public class MessageEnd {

@GET
@Produces(MediaType.TEXT_PLAIN)
@Path("/send")

public String sayHello(){
    return "Hello Jersey";
}
}

I am using jersey 2.11 version My Context root : message When I direct to 我使用的是jersey 2.11版本My Context root:message当我定向到

http://localhost:8080/message/

index.html getting displayed index.html显示

But, when I try to direct 但是,当我尝试指挥

http://localhost:8080/message/rest/send

404 Error is coming. 404错误即将到来。

I have included following jersey files in webapp>WEB-INF>lib directory: 我在webapp> WEB-INF> lib目录中包含以下球衣文件: 在此处输入图片说明

Please guide me. 请指导我。

@Aparna Savant - I am able to "Hello Jersey" when I move @Path("/send") above class declaration. @Aparna Savant-将@Path(“ / send”)移到类声明上方时,我可以“打个招呼”。 – Aparna Savant Aug 11 '14 at 19:10 – 2014年8月11日在19:10的Aparna Savant

Thank you so much for writing this. 非常感谢您撰写本文。 I wasted almost 20 hours trying to fix my api. 我浪费了将近20个小时来尝试修复我的api。

Below is what I did to fix my code. 以下是我修复我的代码所做的事情。

Before 之前

@RestController
@Path("/api")
public class AuxdboAPIResouce {

After

@Path("/api")
@RestController    
public class AuxdboAPIResouce {

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM