jersy示例项目上的HTTP状态404错误

时间:2017-03-07 15:25:20

标签: java jax-rs jax-ws jersey-2.0

我正试图在eclipse中运行一个示例restful web服务应用程序..但是我收到404错误..

Java代码 UserService.java

package com.test;

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

@Path("/UserService")
public class UserService {
    @GET    
    @Path("/users")
    @Produces(MediaType.TEXT_PLAIN)
    public String getUsers() {
        return "Hai";
    }
}

Web.xml中

<?xml version = "1.0" encoding = "UTF-8"?> 
<web-app xmlns:xsi = "http://www.w3.org/2001/XMLSchema-instance"  
   xmlns = "http://java.sun.com/xml/ns/javaee"  
   xsi:schemaLocation="http://java.sun.com/xml/ns/javaee  
   http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"  
   id = "WebApp_ID" version = "3.0"> 
   <display-name>TestWebService</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>TestWebService</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</param-value> 
      </init-param> 
       <load-on-startup>1</load-on-startup>
   </servlet> 
   <servlet-mapping> 
      <servlet-name>TestWebService</servlet-name> 
      <url-pattern>/rest/*</url-pattern> 
   </servlet-mapping>   
</web-app>

当我调用应用程序时出现以下错误。但是我能够获得tomcat主页......

enter image description here

0 个答案:

没有答案