gpt4 book ai didi

java - Tomcat 7.0 服务启动失败,出现 ClassNotFoundException : javax. ws.rs.ProcessingException

转载 作者:行者123 更新时间:2023-11-28 22:30:02 24 4
gpt4 key购买 nike

我有一个玩具 REST Web 服务,我正试图将其部署到 Tomcat 7.0 服务器。问题是我什至无法启动服务器。这是我收到的错误消息:

SEVERE: A child container failed during start java.util.concurrent.ExecutionException: org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Catalina].StandardHost[localhost].StandardContext[/HelloWorldRestService]] at java.util.concurrent.FutureTask.report(FutureTask.java:133) at java.util.concurrent.FutureTask.get(FutureTask.java:199) at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:1123) at org.apache.catalina.core.StandardHost.startInternal(StandardHost.java:800) at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150) at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1559) at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1549) at java.util.concurrent.FutureTask.run(FutureTask.java:273) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1170) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:640) at java.lang.Thread.run(Thread.java:853) Caused by: org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Catalina].StandardHost[localhost].StandardContext[/HelloWorldRestService]] at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:154) ... 6 more

Caused by: java.lang.NoClassDefFoundError: javax.ws.rs.ProcessingException at java.lang.J9VMInternals.prepareClassImpl(Native Method) at java.lang.J9VMInternals.prepare(J9VMInternals.java:1122) at java.lang.Class.getDeclaredFields(Class.java:685) at org.apache.catalina.util.Introspection.getDeclaredFields(Introspection.java:106) at org.apache.catalina.startup.WebAnnotationSet.loadFieldsAnnotation(WebAnnotationSet.java:263) at org.apache.catalina.startup.WebAnnotationSet.loadApplicationServletAnnotations(WebAnnotationSet.java:142) at org.apache.catalina.startup.WebAnnotationSet.loadApplicationAnnotations(WebAnnotationSet.java:67) at org.apache.catalina.startup.ContextConfig.applicationAnnotationsConfig(ContextConfig.java:405) at org.apache.catalina.startup.ContextConfig.configureStart(ContextConfig.java:881) at org.apache.catalina.startup.ContextConfig.lifecycleEvent(ContextConfig.java:376) at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:119) at org.apache.catalina.util.LifecycleBase.fireLifecycleEvent(LifecycleBase.java:90) at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5322) at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150) ... 6 more Caused by: java.lang.ClassNotFoundException: javax.ws.rs.ProcessingException at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1702) at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1547) ... 20 more

SEVERE: A child container failed during start java.util.concurrent.ExecutionException: org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Catalina].StandardHost[localhost]] at java.util.concurrent.FutureTask.report(FutureTask.java:133) at java.util.concurrent.FutureTask.get(FutureTask.java:199) at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:1123) at org.apache.catalina.core.StandardEngine.startInternal(StandardEngine.java:302) at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150) at org.apache.catalina.core.StandardService.startInternal(StandardService.java:443) at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150) at org.apache.catalina.core.StandardServer.startInternal(StandardServer.java:732) at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150) at org.apache.catalina.startup.Catalina.start(Catalina.java:691) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:94) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:55) at java.lang.reflect.Method.invoke(Method.java:619) at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:322) at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:456) Caused by: org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Catalina].StandardHost[localhost]] at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:154) at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1559) at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1549) at java.util.concurrent.FutureTask.run(FutureTask.java:273) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1170) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:640) at java.lang.Thread.run(Thread.java:853) Caused by: org.apache.catalina.LifecycleException: A child container failed during start at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:1131) at org.apache.catalina.core.StandardHost.startInternal(StandardHost.java:800) at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150) ... 6 more

SEVERE: The required Server component failed to start so Tomcat is unable to start. org.apache.catalina.LifecycleException: Failed to start component [StandardServer[8005]] at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:154) at org.apache.catalina.startup.Catalina.start(Catalina.java:691) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:94) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:55) at java.lang.reflect.Method.invoke(Method.java:619) at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:322) at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:456) Caused by: org.apache.catalina.LifecycleException: Failed to start component [StandardService[Catalina]] at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:154) at org.apache.catalina.core.StandardServer.startInternal(StandardServer.java:732) at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150) ... 7 more Caused by: org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Catalina]] at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:154) at org.apache.catalina.core.StandardService.startInternal(StandardService.java:443) at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150) ... 9 more Caused by: org.apache.catalina.LifecycleException: A child container failed during start at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:1131) at org.apache.catalina.core.StandardEngine.startInternal(StandardEngine.java:302) at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150) ... 11 more

我正在使用 Jersey 2.x。这是我的 jar :

javax.ws.rs-api-2.0-m10.jar

Jersey 客户端.jar

Jersey -common.jar

jersey-container-servlet.jar

Jersey -容器-servlet-core.jar

Jersey 服务器.jar

我的 web.xml 如下所示:

<?xml version="1.0" encoding="UTF-8"?>
<web-app id="WebApp_ID" version="3.0" xmlns="http://java.sun.com/xml/ns/javaee xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd">
<display-name>HelloWorldRestService</display-name>
<servlet>
<servlet-name>java.helloworldrestservice.resources.HelloWorldApplication</servlet-name>
<servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class>

<!-- Register JAX-RS Application, if needed. -->
<init-param>
<param-name>javax.ws.rs.Application</param-name>
<param-value>java.helloworldrestservice.resources.HelloWorldApplication</param-value>
</init-param>

<!-- Register resources and providers under my.package. -->
<init-param>
<param-name>jersey.config.server.provider.packages</param-name>
<param-value>java.helloworldrestservice.resources</param-value>
</init-param>

<!-- Enable Tracing support. -->
<init-param>
<param-name>jersey.config.server.tracing</param-name>
<param-value>ALL</param-value>
</init-param>

<load-on-startup>1</load-on-startup>
</servlet>

<servlet-mapping>
<servlet-name>java.helloworldrestservice.resources.HelloWorldApplication</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>

HelloWorldApplication.java:

package java.helloworldrestservice.resources;

import java.util.HashSet;
import java.util.Set;
import javax.ws.rs.core.Application;


public class HelloWorldApplication extends Application
{

@Override
public Set<Class<?>> getClasses()
{
//log.info("starting the HelloWorld application...");
Set<Class<?>> set = new HashSet<Class<?>>();
set.add(HelloWorld.class);
return set;
}
}

HelloWorld.java:

package java.helloworldrestservice.resources;


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

@Path("/hello")
public class HelloWorld {
@GET
@Produces(MediaType.TEXT_PLAIN)
public String sayPlainTextHello()
{
return "Hello World!!";
}
}

怎么了?为什么我会看到这个缺少的 ProcessingException 类,我该如何摆脱这个错误?

非常感谢!

最佳答案

javax.ws.rs.ProcessingException 似乎是 javax.ws.rs 包的一部分,它是 rest 的一部分,但默认情况下不随 Java 或 Tomcat 一起提供。

它似乎包含在 javax.ws.rs-api-2.0.jar 等内容中。 Maven 存储库中还有一个 javax.ws.rs 版本。

看起来 Jersey REFERENCES 但没有实现这个类。

https://jersey.java.net/apidocs/2.6/jersey/javax/ws/rs/class-use/ProcessingException.html

因此您需要下载相应的 jar 并将其包含在您的类路径中,以便它能够使用 ProcessingException 并启动您的容器。

看了看。我希望 Jersey.java.net 会提供这个库作为他们的包的一部分。如果他们不这样做,您将不得不自己从 Maven 中提取 REST 先决条件。

关于java - Tomcat 7.0 服务启动失败,出现 ClassNotFoundException : javax. ws.rs.ProcessingException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23784582/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com