分享

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

 印度阿三17 2020-02-06

以下方法适用于基于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包

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多