首页 > 编程语言> > The following method did not exist:javax.servlet.ServletContext.getVirtualServerName()Ljava/lang/Str
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
模式,成功排除了冲突依赖:
标签:lang,Ljava,依赖,String,jar,ServletContext,following,servlet,javax 来源: https://www.cnblogs.com/langkyeSir/p/15301926.html