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

0.报错

springboot 项目,打包部署到服务器有时启动项目报错


***************************
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:/data01/datax/datax-web-2.1.2/modules/datax-admin/lib/servlet-api-2.4.jar!/javax/servlet/ServletContext.class
    jar:file:/data01/datax/datax-web-2.1.2/modules/datax-admin/lib/tomcat-embed-core-9.0.17.jar!/javax/servlet/ServletContext.class

It was loaded from the following location:

    file:/data01/datax/datax-web-2.1.2/modules/datax-admin/lib/servlet-api-2.4.jar


Action:

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

javax.servlet.ServletContext 这个类有两个来源

  • servlet-api-2.4.jar
  • tomcat-embed-core-9.0.17.jar
    这两个类都有导致冲突了,目前系统加载的是servlet-api-2.4.jar下的ServletContext.

我们应该使用springboot自带tomcat,而不是额外 lib目录下的jar包,所以按提示取目录下删除就可以了

1.排查与解决

额外 lib/servlet-api-2.4.jar 肯定是pom某个依赖带来的,如何排除?

mvn dependency:tree >out.txt

通过maven的命令行:mvn dependency:tree 来查看Maven依赖信息,落成out.txt文件,搜索 servlet-api发现

[INFO] ± jcifs:jcifs:jar:1.3.17:compile
[INFO] | - javax.servlet:servlet-api:jar:2.4:compile

可以看到servlet-api-2.4.jar是通过jcifs这个jar引入进来的,我们在pom.xml里找到它手动排除就可以了

pom.xml

       <dependency>
            <groupId>jcifs</groupId>
            <artifactId>jcifs</artifactId>
            <version>1.3.17</version>
            <exclusions>
                <exclusion>
                    <artifactId>servlet-api</artifactId>
                    <groupId>javax.servlet</groupId>
                </exclusion>
            </exclusions>
        </dependency>

你可能感兴趣的:(报错集合,spring,boot)