解决javax.servlet.ServletContext.getVirtualServerName()Ljava/lang/String;

SpringBoot应用启动失败解决
本文解决了一个基于SpringBoot的应用启动失败的问题,错误源于项目中存在两个不同版本的javax.servlet-api.jar库,导致方法调用冲突。解决方案是删除多余的库,确保项目使用正确的Maven依赖。

以下方法适用于基于spring boot的应用

先看以下报错信息:



Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2019-04-28 17:31:14.186 ERROR 12404 --- [           main] o.s.b.d.LoggingFailureAnalysisReporter   : 

***************************
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:1178)

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:/F:/jdk/jre/lib/ext/servlet-api.jar!/javax/servlet/ServletContext.class
   jar:file:/C:\Users\fan\.m2\repository\javax\servlet\javax.servlet-api\3.1.0\javax.servlet-api-3.1.0.jar!/javax/servlet/ServletContext.class
t was loaded from the following location:
    jar:file:/F:/jdk/jre/lib/ext/servlet-api.jar!/javax/servlet/ServletContext.class


Action:

Correct the classpath of your application so that it contains a single, compatible version of javax.servlet.ServletContext


Process finished with exit code 1

注意一下这句话:

The method's class, javax.persistence.Table, is available from the following locations:
jar:file:/F:/jdk/jre/lib/ext/servlet-api.jar!/javax/servlet/ServletContext.class
jar:file:/C:\Users\fan\.m2\repository\javax\servlet\javax.servlet-api\3.1.0\javax.servlet-api-3.1.0.jar!/javax/servlet/ServletContext.class

大致是说本地有两个javax.servlet-api.jar 库, 而项目启动时使用了错误的那个库,导致找不到对应方法。解决办法就是删掉一个。

因为我的项目是基于maven的,所以项目应该使用maven下载的jar,F盘的那个显然是不需要的(maven下载的jar包默认存放位置为c盘user目录下的.m2文件夹内),所以删除掉F:/jdk/jre/lib/ext/servlet-api.jar就搞定了。

ps:如果是环境用的是idea,可能需要先关闭idea才能删除目标jar包

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:1200) The following method did not exist: javax.servlet.ServletContext.getVirtualServerName()Ljava/lang/String; The calling method's class, org.apache.catalina.authenticator.AuthenticatorBase, was loaded from the following location: jar:file:/D:/Maven/repository/org/apache/tomcat/embed/tomcat-embed-core/9.0.96/tomcat-embed-core-9.0.96.jar!/org/apache/catalina/authenticator/AuthenticatorBase.class The called method's class, javax.servlet.ServletContext, is available from the following locations: jar:file:/D:/Maven/repository/javax/servlet/servlet-api/2.5/servlet-api-2.5.jar!/javax/servlet/ServletContext.class jar:file:/D:/Maven/repository/javax/servlet/javax.servlet-api/4.0.1/javax.servlet-api-4.0.1.jar!/javax/servlet/ServletContext.class jar:file:/D:/Maven/repository/org/apache/tomcat/embed/tomcat-embed-core/9.0.96/tomcat-embed-core-9.0.96.jar!/javax/servlet/ServletContext.class The called method's class hierarchy was loaded from the following locations: javax.servlet.ServletContext: file:/D:/Maven/repository/javax/servlet/servlet-api/2.5/servlet-api-2.5.jar Action: Correct the classpath of your application so that it contains compatible versions of the classes org.apache.catalina.authenticator.AuthenticatorBase and javax.servlet.ServletContext 16:23:59.301 [Thread-15] WARN c.a.n.c.n.NotifyCenter - [shutdown,136] - [NotifyCenter] Start destroying Publisher 16:23:59.301 [Thread-10] WARN c.a.n.c.h.HttpClientBeanHolder - [shutdown,102] - [HttpClientBeanHolder] Start destroying common HttpClient 16:23:59.301 [Thread-15] WARN c.a.n.c.n.NotifyCenter - [shutdown,153] - [NotifyCenter] Destruction of the end
最新发布
03-22
评论 6
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值