报错信息如下:
***************************
APPLICATION FAILED TO START
***************************
Description:
An attempt was made to call the method javax.servlet.ServletContext.getVirtualServerName()Ljava/lang/String; but it does not exist. Its class, javax.servlet.ServletContext, is available from the following locations:
jar:file:/D:/MyProjects/JavaProject/apache-maven-3.3.9/local_ware/javax/servlet/servlet-api/2.3/servlet-api-2.3.jar!/javax/servlet/ServletContext.class
jar:file:/D:/MyProjects/JavaProject/apache-maven-3.3.9/local_ware/org/apache/tomcat/embed/tomcat-embed-core/8.5.34/tomcat-embed-core-8.5.34.jar!/javax/servlet/ServletContext.class
It was loaded from the following location:
file:/D:/MyProjects/JavaProject/apache-maven-3.3.9/local_ware/javax/servlet/servlet-api/2.3/servlet-api-2.3.jar
Action:
Correct the classpath of your application so that it contains a single, compatible version of javax.servlet.ServletContext
Disconnected from the target VM, address: '127.0.0.1:58339', transport: 'socket'
Process finished with exit code 1
原因就是引入的jar包发生了依赖冲突:
解决方案有两种:1、删除本地目录下的冲突jar包
比如我的提示信息:
It was loaded from the following location:
file:/D:/MyProjects/JavaProject/apache-maven-3.3.9/local_ware/javax/servlet/servlet-api/2.3/servlet-api-2.3.jar
我就可以删除我在d盘里面对应的servlet-api-2.3.jar即可
2、在终端使用命令mvn dependency:tree看一下依赖关系,判断产生冲突的依赖是哪个,然后将pom文件下的冲突依赖删掉一个