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

以下方法適用於基於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包

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章