"java.lang.ClassNotFoundException: javax.ws.rs.ProcessingException" При создании веб-Api Rest - PullRequest
0 голосов
/ 13 декабря 2018

Я пытаюсь создать простой 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

Из-за создания в первый раз, я мог бы добавить несколько банок, которые совсем не нужны.Пожалуйста, предложите то же самое.

Мой 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>

Это конфигурация моего сервера

Я пытаюсь получить доступ с помощью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)
...