异常1:jar包冲突类冲突ServletContext.class
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: 尝试调用方法javax.servlet.ServletContext.getVirtualServerName();但它并不存在。
它的类,javax.servlet。ServletContext,可从以下位置获得: jar:file:/E:/Software/apache-maven-3.5.3/repository/org/mortbay/jetty/servlet-api-2.5/6.1.14/servlet-api-2.5-6.1.14.jar!/javax/servlet/ServletContext.class jar:file:/E:/Software/apache-maven-3.5.3/repository/javax/servlet/servlet-api/2.5/servlet-api-2.5.jar!/javax/servlet/ServletContext.class jar:file:/E:/Software/apache-maven-3.5.3/repository/org/apache/tomcat/embed/tomcat-embed-core/8.5.39/tomcat-embed-core-8.5.39.jar!/javax/servlet/ServletContext.class It was loaded from the following location:
它是从以下地点加载的: file:/E:/Software/apache-maven-3.5.3/repository/org/mortbay/jetty/servlet-api-2.5/6.1.14/servlet-api-2.5-6.1.14.jar Action: Correct the classpath of your application so that it contains a single, compatible version of javax.servlet.ServletContext
原因:从错误信息看出,在tomcat-embed-core-9.0.17.jar和servlet-api-2.5.jar里面都有javax.servlet.ServletContext, 而这个类在eureka中使用默认用了servlet-api-2.5.jar进行。经过查看发现,servlet-api-2.5.jar是eureka里面引进来的
解决:
方法1(不推荐)
Project Structure----Modules—微服务----Dependences
重复依赖仅保留一个其余改为Test或删除,删除或者改为test
方法2
添加:
<exclusion>
<groupId>org.apache.shiro</groupId>
<artifactId>shiro-quartz</artifactId>
</exclusion>
例如:
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-server</artifactId>
<version>2.1.3.RELEASE</version>
<exclusions>
<exclusion>
<artifactId>servlet-api