当 Spring Boot 启动时,它会引发“方法名称必须是令牌”异常

2022-08-31 15:22:19

当 Spring Boot 启动时,它会引发异常method names must be tokens

2016-08-11 16:53:54.499  INFO 14212 --- [0.1-8888-exec-1] o.apache.coyote.http11.Http11Processor   : Error parsing HTTP request header
 Note: further occurrences of HTTP header parsing errors will be logged at DEBUG level.

java.lang.IllegalArgumentException: Invalid character found in method name. HTTP method names must be tokens
        at org.apache.coyote.http11.Http11InputBuffer.parseRequestLine(Http11InputBuffer.java:462) ~[tomcat-embed-core-8.5.4.jar!/:8.5.4]
        at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:994) ~[tomcat-embed-core-8.5.4.jar!/:8.5.4]
        at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66) [tomcat-embed-core-8.5.4.jar!/:8.5.4]
        at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:785) [tomcat-embed-core-8.5.4.jar!/:8.5.4]
        at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1425) [tomcat-embed-core-8.5.4.jar!/:8.5.4]
        at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49) [tomcat-embed-core-8.5.4.jar!/:8.5.4]
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) [na:1.8.0_72]
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) [na:1.8.0_72]
        at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) [tomcat-embed-core-8.5.4.jar!/:8.5.4]
        at java.lang.Thread.run(Thread.java:745) [na:1.8.0_72]

2016-08-11 16:53:58.885  INFO 14212 --- [0.1-8888-exec-2] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring FrameworkServlet 'dispatcherServlet'
2016-08-11 16:53:58.888  INFO 14212 --- [0.1-8888-exec-2] o.s.web.servlet.DispatcherServlet        : FrameworkServlet 'dispatcherServlet': initialization started
2016-08-11 16:53:58.922  INFO 14212 --- [0.1-8888-exec-2] o.s.web.servlet.DispatcherServlet        : FrameworkServlet 'dispatcherServlet': initialization completed in 30 ms
11111111-chinadfadf-xxxxxxxx@121.com

有谁知道为什么它会引发这个异常?


答案 1

当您尝试在未启用 https 的终结点上执行来自客户端的 https 请求时,可能会发生此异常。当服务器需要原始数据时,客户端将加密请求数据。

在客户端 url 中将 https:// 更改为 http://。


答案 2

另一种情况:SpringBoot和Tomcat默认使用端口8080或8888。我有一个Jupyter Notebook同时运行,它的url路径中有一个令牌和一些随机字符。无论如何:当 jupyter 笔记本服务器关闭时,笔记本仍在尝试发出请求。

如果遇到此错误:请检查是否正在运行另一个应用程序,该应用程序正在生成 Web 服务器或与此类端口上的 Web 服务器通信。


推荐