一、启动SpringBoot失败,异常信息如下
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:/Users/ac/.gradle/caches/modules-2/files-2.1/javax.servlet/servlet-api/2.4/3fc542fe8bb8164e8d3e840fe7403bc0518053c0/servlet-api-2.4.jar!/javax/servlet/ServletContext.class
jar:file:/Users/ac/.gradle/caches/modules-2/files-2.1/org.apache.tomcat.embed/tomcat-embed-core/8.5.34/a038040d68a90397f95dd1e11b979fe364a5000f/tomcat-embed-core-8.5.34.jar!/javax/servlet/ServletContext.class
It was loaded from the following location:
file:/Users/ac/.gradle/caches/modules-2/files-2.1/javax.servlet/servlet-api/2.4/3fc542fe8bb8164e8d3e840fe7403bc0518053c0/servlet-api-2.4.jar
二、解决
servlet-api版本太低,升级即可
剔除旧版本
configurations {
compile.exclude module: 'servlet-api'
}
配置新版本
compileOnly group: 'javax.servlet', name: 'javax.servlet-api', version: '4.0.1'