ResourceConfig实例不包含任何根资源类(eclipse tomcat)

时间:2018-12-11 11:36:03

标签: java rest tomcat server jersey

首先要说的是,我尝试了我在stackoverflow和其他网站上遇到的所有问题。第二点是,我正在根据老师给我们的示例项目构建代码,该代码在我的计算机上运行良好。我遵循他项目的每个步骤,但是当我尝试通过此链接访问数据时,我的版本出现以下错误

  

http://localhost:8080/Cinema.Server/rest/users

javax.servlet.ServletException: "Servlet.init()" for the servlet [Jersey REST Service] has generated an exception + com.sun.jersey.api.container.ContainerException: The ResourceConfig instance does not contain any root resource classes.

我的老师出去了一周,我将继续尝试解决此问题,但是如果您发现有什么帮助的话,请说。

标题

package cinema.server.ressources;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import javax.servlet.http.HttpServletResponse;
import javax.ws.rs.Consumes;
import javax.ws.rs.FormParam;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Request;
import javax.ws.rs.core.UriInfo;
import javax.xml.bind.annotation.XmlRootElement;
import com.sun.xml.internal.txw2.annotation.XmlElement;
import cinema.server.user.*;
import cinema.server.users.*;
@XmlRootElement(name="UsersRessources")
@Path("/users")
public class UsersRessources {
      // Allows to insert contextual objects into the class, 
      // e.g. ServletContext, Request, Response, UriInfo
      @Context
      UriInfo uriInfo;
      @Context
      Request request;


      // Return the list of Users to the user in the browser
      @GET
      @Produces(MediaType.TEXT_XML)
      public List<User> getUsersBrowser() {
        List<User> MyUsers = new ArrayList<User>();
        MyUsers.addAll(Users.instance.getUsers());
        return MyUsers; 
      }
    /* Return the list of Users for applications
      @GET
      @Produces(MediaType.APPLICATION_JSON)
      public List<User> getUsers() {
        List<User> MyUsers = new ArrayList<User>();
        MyUsers.addAll(Users.instance.getUsers());
        return MyUsers; 
      }
      */
      //Create a new User
      @POST
      @Path("/create")
      @Produces(MediaType.TEXT_HTML)
      @Consumes(MediaType.APPLICATION_FORM_URLENCODED)
      public void newUser(@FormParam("id") String id,
          @FormParam("password") String password,
          @Context HttpServletResponse servletResponse) throws IOException {
        User session = new User(id,password);
        Users.instance.getUsers().add(session);

        servletResponse.sendRedirect("../users.html");
      }
}

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" 
   xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
   xsi:schemaLocation="http://java.sun.com/xml/ns/javaee 
   http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
   id="WebApp_ID" version="2.5">
  <display-name>Cinema.Server</display-name>
  <servlet>
    <servlet-name>Jersey REST Service</servlet-name>
    <servlet-class>com.sun.jersey.spi.container.servlet.ServletContainer</servlet-class>
    <init-param>
      <param-name>com.sun.jersey.config.property.packages</param-name>
      <param-value>cinema.server.ressources</param-value>
    </init-param>
    <load-on-startup>1</load-on-startup>
  </servlet>
  <servlet-mapping>
    <servlet-name>Jersey REST Service</servlet-name>
    <url-pattern>/rest/*</url-pattern>
  </servlet-mapping>
</web-app>
---------

网络应用程序库

asm-3.1.jar
jackson-core-asl-1.9.2.jar
jackson-jaxrs-1.9.2.jar
jackson-mapper-asl-1.9.2.jar
jackson-xc-1.9.2.jar
jersey-client-1.17.jar
jersey-core-1.17.jar
jersey-json-1.17.jar
jersey-server-1.17.jar
jersey-servlet-1.17.jar
jettison-1.1.jar
jsr311-api-1.1.1.jar

Server Side Structure

0 个答案:

没有答案