Java servlet [dispatcherServlet] 的 Servlet.service() 在路径 [] 的上下文中引发异常

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/49298719/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-12 02:59:23  来源:igfitidea点击:

Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception

javaspringtomcatweb

提问by breaktop

I have a spring boot application that is throwing the following:

我有一个 spring boot 应用程序抛出以下内容:

2018-01-14 01:02:56.863 ERROR 372 --- [io-8080-exec-14] o.a.c.c.C.[.[.[/].[dispatcherServlet] : Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is java.lang.NullPointerException] with root cause

2018-01-14 01:02:56.863 错误 372 --- [io-8080-exec-14] oaccC[.[.[/].[dispatcherServlet] : Servlet.service() for servlet [dispatcherServlet] 在上下文中路径[]抛出异常[请求处理失败;嵌套异常是 java.lang.NullPointerException] 具有根本原因

The application runs and behaves as expected. I've seen the error in the logs a few times but can't seem to see why/where its happening.

应用程序按预期运行和运行。我在日志中看到过几次错误,但似乎看不到它发生的原因/位置。

There is no other information in the log about the error.

日志中没有关于错误的其他信息。

I've had a look at the logs to see what happened before and after the error occurred and everything seemed fine.

我查看了日志以了解错误发生前后发生的情况,一切似乎都很好。

I have also turned the log level to ALL and still the no useful error message.

我还将日志级别设置为 ALL,但仍然没有有用的错误消息。

Any ideas why I am getting this error and how I can get my application to throw more useful errors.

任何想法为什么我会收到此错误以及如何让我的应用程序抛出更多有用的错误。

What stand out from the error message is with path [] threw exception. I'm not sure what []is.

从错误消息中脱颖而出的是with path [] threw exception. 我不确定是什么[]

回答by Johannes Leimer

Any ideas why I am getting this error and how I can get my application to throw more useful errors.

任何想法为什么我会收到此错误以及如何让我的应用程序抛出更多有用的错误。

The root cause is a NullPointerException(NPE) thrown at some point in the call stack of the DispatcherServlet.

根本原因是NullPointerExceptionDispatcherServlet.

Unfortunately, you don't get a complete stacktrace of the NPE in your log. Have you checkout the standard output for the stacktrace? Normally Spring Boot is really conservative configured when it comes to swallowing stacktraces. Meaning: there should be a point where you can see the complete stacktrace. My guess: a logfile in the working directory or the standard output of the application (e.g. terminal screen).

不幸的是,您没有在日志中获得 NPE 的完整堆栈跟踪。您是否检查了堆栈跟踪的标准输出?通常情况下,Spring Boot 在吞咽堆栈跟踪方面的配置非常保守。意思是:应该有一个点可以看到完整的堆栈跟踪。我的猜测:工作目录中的日志文件或应用程序的标准输出(例如终端屏幕)。

What stand out from the error message is with path [] threw exception. I'm not sure what [] is.

从错误消息中脱颖而出的是路径 [] 抛出异常。我不确定 [] 是什么。

This is the path part of the request. []means the path is an empty string. Spring used the []-notation to signal you that there is an empty string. Normally it would look like [/users/34]. My guess is: you called something like http://localhost:8080so no trailing slash is present, which renders the path part of the url to an empty string.

这是请求的路径部分。[]表示路径是空字符串。Spring 使用[]-notation 来表示有一个空字符串。通常它看起来像[/users/34]. 我的猜测是:你调用了类似的东西,http://localhost:8080所以不存在尾部斜杠,这会将 url 的路径部分呈现为空字符串。

回答by Chris K.

I had the same issue and was able to resolve it by using another JDK.

我遇到了同样的问题,并且能够通过使用另一个 JDK 来解决它。

I switched from openjdk 8 to openjdk 9 (both ubuntu 18.04) by running

我通过运行从 openjdk 8 切换到 openjdk 9(均为 ubuntu 18.04)

sudo apt install default-jdk

sudo apt install default-jdk

(check if it update your symlinks with java -version

(检查它是否更新您的符号链接 java -version