Rest get和post方法返回404错误

时间:2017-05-25 00:52:45

标签: java rest java-ee

我有以下代码(由其他人编码)和各种Rest注释:

package org.koushik.javabrains.messenger.resource;

import java.util.List;
// removed most of import.javax..... imports, to avoid error: it looks like mostly code


import org.koushik.javabrains.messenger.model.Message;
import org.koushik.javabrains.messenger.service.MessageService;

@Path("/messages")
public class MessageResource {
    MessageService messageService = new MessageService();

@GET
@Produces(MediaType.APPLICATION_JSON)
public List<Message> getMessages() {
    return messageService.getAllMessages();
    }
}

我正在使用邮递员休息客户端,在404上使用所有这三种方法时,我收到http://localhost:8080/messenger/webapi/messages响应。

的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.koushik.javabrains.messenger</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>

0 个答案:

没有答案