创建Rest Web-Api时出现“ java.lang.ClassNotFoundException:javax.ws.rs.ProcessingException”

时间:2018-12-13 10:43:21

标签: json rest api restful-url

我正在尝试制作一个简单的rest-api,它将返回JSON中的值。

我的服务等级是:-

import java.util.List;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;


@Path("/UserService") 
public class UserService { 

@GET
@Path("test")
@Produces(MediaType.APPLICATION_JSON)
public User getMyBean() {
   User oUser = new User(); 
   oUser.setName("Srijib");
   oUser.setId(7);
   oUser.setProfession("Student");
   return oUser;
}}

用户类别:-

import java.io.Serializable;  
import javax.xml.bind.annotation.XmlElement; 
import javax.xml.bind.annotation.XmlRootElement; 
@XmlRootElement(name = "user") 

public class User implements Serializable {  
   private static final long serialVersionUID = 1L; 
   private int id; 
   private String name; 
   private String profession; 
   public int getId() { 
      return id; 
   }  
   @XmlElement 
       public void setId(int id) { 
      this.id = id; 
   } 
   public String getName() { 
      return name; 
   } 
   @XmlElement
   public void setName(String name) { 
      this.name = name; 
   } 
   public String getProfession() { 
      return profession; 
   } 
   @XmlElement 
   public void setProfession(String profession) { 
      this.profession = profession; 
   }   
} 

我的图书馆:-

aopalliance-repackaged-2.4.0-b34.jar
ehcache-1.2.3.jar
ehcache-core-2.3.1.jar
hk2-api-2.4.0-b34.jar
hk2-locator-2.4.0-b34.jar
hk2-utils-2.4.0-b34.jar
jackson-annotations-2.2.3.jar
jackson-core-2.2.3.jar
jackson-databind-2.2.3.jar
jackson-jaxrs-base-2.2.3.jar
jackson-jaxrs-json-provider-2.2.3.jar
jackson-module-jaxb-annotations-2.2.3.jar
javassist-3.18.1-GA.jar
javax.annotation-api-1.2.jar
javax.inject-2.4.0-b34.jar
javax.ws.rs-api-2.0.1.jar
jaxb-api-2.2.7.jar
jersey-client-2.23.1.jar
jersey-common-2.23.1.jar
jersey-container-servlet-2.23.1.jar
jersey-container-servlet-core-2.23.1.jar
jersey-guava-2.23.1.jar
jersey-media-jaxb-2.23.1.jar
jersey-media-json-jackson-2.25.jar
jersey-media-moxy-2.7.jar
jersey-server-2.23.1.jar
jfxrt.jar
org.osgi.core-4.2.0.jar
org.springframework.core-3.0.4.RELEASE.jar
osgi-resource-locator-1.0.1.jar
persistence-api-1.0.jar
SIFFramework.jar
validation-api-1.1.0.Final.jar

由于是第一次创建,所以我可能添加了一些根本不需要的jar。请提出同样的建议。

我的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>UserManagement</display-name> 
   <servlet> 
      <servlet-name>Jersey RESTful 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.tutorialspoint</param-value> 
      </init-param> 
   </servlet> 
   <servlet-mapping> 
      <servlet-name>Jersey RESTful Application</servlet-name> 
      <url-pattern>/rest/*</url-pattern> 
   </servlet-mapping>   
</web-app>

This is my server configuration

我正在尝试使用以下URL访问:-     http://localhost:8080/UserManagement/rest/UserService/test

我尝试访问URL时遇到的错误是:-

SEVERE: Allocate exception for servlet Jersey RESTful Application
java.lang.ClassNotFoundException: javax.ws.rs.ProcessingException
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1680)
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1526)
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(Unknown Source)
at java.security.SecureClassLoader.defineClass(Unknown Source)
at org.apache.catalina.loader.WebappClassLoader.findClassInternal(WebappClassLoader.java:2818)
at org.apache.catalina.loader.WebappClassLoader.findClass(WebappClassLoader.java:1159)
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1647)
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1526)
at java.lang.Class.getDeclaredConstructors0(Native Method)
at java.lang.Class.privateGetDeclaredConstructors(Unknown Source)
at java.lang.Class.getConstructor0(Unknown Source)
at java.lang.Class.newInstance0(Unknown Source)
at java.lang.Class.newInstance(Unknown Source)
at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1149)
at org.apache.catalina.core.StandardWrapper.allocate(StandardWrapper.java:827)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:129)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:293)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:859)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:602)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
at java.lang.Thread.run(Unknown Source)

0 个答案:

没有答案