The following method did not exist:javax.servlet.ServletContext.getVirtualServerName()Ljava/lang/Str
2021/9/16 22:05:22
本文主要是介绍The following method did not exist:javax.servlet.ServletContext.getVirtualServerName()Ljava/lang/Str,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
SpringBoot 启动失败。又是
jar
冲突,这是第几次了?
报错细节
报错细节:
*************************** APPLICATION FAILED TO START *************************** Description: An attempt was made to call a method that does not exist. The attempt was made from the following location: org.apache.catalina.authenticator.AuthenticatorBase.startInternal(AuthenticatorBase.java:1355) The following method did not exist: javax.servlet.ServletContext.getVirtualServerName()Ljava/lang/String; The method's class, javax.servlet.ServletContext, is available from the following locations: jar:file:/opt/ETC/xxl-job-executor-etc/run/lib/servlet-api-2.5.jar!/javax/servlet/ServletContext.class jar:file:/opt/ETC/xxl-job-executor-etc/run/lib/tomcat-embed-core-9.0.41.jar!/javax/servlet/ServletContext.class The class hierarchy was loaded from the following locations: javax.servlet.ServletContext: file:/opt/ETC/xxl-job-executor-etc/run/lib/servlet-api-2.5.jar Action: Correct the classpath of your application so that it contains a single, compatible version of javax.servlet.ServletContext
分析错误
描述信息大概意思是:你在调用一个不存在的方法,该方法可以在xxx位置找到。
what fk ?看到17行
、18行
瞬间反应过来,这个方法在两个jar中都有,并且类路径完全相同,jre懵逼了,不知道调用哪个,然后将问题抛出来给开发者:你必须让我能够明确知道调用哪个。
接下来事情就明确了,我们需要剔除多余的重复jar
,本次示例的冲突是servlet-api
,由于SpringBoot
默认是使用内嵌的tomcat
启动,所以应该是其他的依赖中重复导入了这个依赖,直接进行排除就OK了。
怎么排出重复依赖?
-
第一步:检查pom有没有显示的引入冲突的依赖,如果有,remove 它,基本没问题了。
-
第二步:如果第一步没有解决,那就是被其他的依赖导入了,下面就演示一下排出依赖的步骤(以下通过
IDEA
进行maven依赖排出)打开
pom.xml
(平时我们浏览、编辑都是在Text
模式下):切换到
Dependency Analyzer
模式下:搜索
servlet-api
:排出依赖:右击选择的依赖,选择
Exclude
。切换到
Text
模式,成功排除了冲突依赖:
这篇关于The following method did not exist:javax.servlet.ServletContext.getVirtualServerName()Ljava/lang/Str的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2024-09-28微服务架构中API版本控制的实践
- 2024-09-28AI给的和自己写的Python代码,都无法改变输入框的内容,替换也不行
- 2024-09-27Sentinel配置限流资料:新手入门教程
- 2024-09-27Sentinel配置限流资料详解
- 2024-09-27Sentinel限流资料:新手入门教程
- 2024-09-26Sentinel限流资料入门详解
- 2024-09-26Springboot框架资料:初学者入门教程
- 2024-09-26Springboot框架资料详解:新手入门教程
- 2024-09-26Springboot企业级开发资料:新手入门指南
- 2024-09-26SpringBoot企业级开发资料新手指南