是什么原因引起的?这似乎是一个非常混乱的原因。
HTTP Status 500 -
type Exception report
message
description The server encountered an internal error that prevented it from fulfilling this request.
exception
java.lang.NullPointerException
java.util.concurrent.ConcurrentHashMap.putVal(Unknown Source)
java.util.concurrent.ConcurrentHashMap.putIfAbsent(Unknown Source)
java.lang.ClassLoader.getClassLoadingLock(Unknown Source)
org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1149)
org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1116)
org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:510)
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79)
org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:620)
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:349)
org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:1110)
org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66)
org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:785)
org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1425)
org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:52)
java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
java.lang.Thread.run(Unknown Source)
note The full stack trace of the root cause is available in the Apache Tomcat/8.5.3 logs.
以下是包含:
import java.util.Set;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.Application;
添加web.xml 请注意:我已经为url-pattern尝试了多个值,它似乎只是更改了我得到错误的URI。 'Hello'是java源代码中的类名。
<?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" version="3.0">
<servlet>
<servlet-name>HelloWorldTomcatService</servlet-name>
<init-param>
<param-name>com.package.from.java.file</param-name>
<param-value>Hello</param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>HelloWorldTomcatService</servlet-name>
<url-pattern></url-pattern>
</servlet-mapping>
<session-config>
<session-timeout>30</session-timeout>
</session-config>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
</web-app>
答案 0 :(得分:2)
java.lang.NullPointerException
java.util.concurrent.ConcurrentHashMap.putVal(Unknown Source)
java.util.concurrent.ConcurrentHashMap.putIfAbsent(Unknown Source)
java.lang.ClassLoader.getClassLoadingLock(Unknown Source)
org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1149)
此特定条目可能是由web.xml
条目引起的,该条目需要<xxx-class>
,例如<servlet-class>
,<filter-class>
或<listener-class>
,但它实际上不存在或空。
事实上,您的<servlet>
条目缺少<servlet-class>
。它应该引用servlet类的FQN,你想在<servlet-name>
指定的名称下注册,如下所示。
<servlet>
<servlet-name>someServlet</servlet-name>
<servlet-class>com.example.SomeServlet</servlet-class>
</servlet>
也就是说,如果它实际上是您尝试注册的JAX-RS servlet,那么<init-param><param-name>
也看起来不太好。您确定您正在阅读正确的教程/资源,以学习JAX-RS并将其集成到Tomcat中吗?众所周知的是由Lars Vogel提供的。