RestEasy Web服务无法使用指定的URL获取响应?

时间:2015-04-14 12:03:13

标签: java web-services resteasy

我是网络服务新手。我在RestEasy网络服务中遇到了一个奇怪的问题。 当我点击网络服务URL时,低于error.Plase让我知道我在做错误的地方。 谢谢,

HTTP Status 404 - Could not find resource for relative : /rest/publish of full path: http://localhost:8888/WebServiceJaskson/rest/publish 

的web.xml。

   <display-name>WebServiceJaskson</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> 
<context-param>
        <param-name>resteasy.scan</param-name>
        <param-value>true</param-value>
    </context-param>

    <listener>
        <listener-class>
            org.jboss.resteasy.plugins.server.servlet.ResteasyBootstrap
        </listener-class>
    </listener>

    <servlet>
        <servlet-name>resteasy-servlet</servlet-name>
        <servlet-class>
            org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher
        </servlet-class>
    </servlet>

    <servlet-mapping>
        <servlet-name>resteasy-servlet</servlet-name>
        <url-pattern>/rest/*</url-pattern>
    </servlet-mapping>

RestEasyService.java

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.core.Response;


@Path("/publish")
public class RestEasyService {

    @GET
    @Produces(MediaType.TEXT_HTML)
    public Response getRestResponse(){
        return Response.status(200).entity("<b>Rest Web Response</b>").build(); 
    }
}

1 个答案:

答案 0 :(得分:2)

您需要将context-param resteasy.servlet.mapping.prefix添加到您的web.xml。

<context-param>
    <param-name>resteasy.servlet.mapping.prefix</param-name>
    <param-value>/rest</param-value>
</context-param>