解决springCloud整合eureka 时,javax.servlet.ServletContext.getVirtualServerName()找不到错误。
springboot版本是2.1.4.RELEASEspring-cloud-dependencies版本为:Greenwich.SR3eureka版本为:2.1.3.RELEASE整合后启动,出现如下报错:Description:An attempt was made to call a method that does not exist. The att...
springboot版本是
2.1.4.RELEASE
spring-cloud-dependencies版本为:
Greenwich.SR3
eureka版本为:
2.1.3.RELEASE
整合后启动,出现如下报错:
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:/G:/mavenRepo/javax/servlet/servlet-api/2.5/servlet-api-2.5.jar!/javax/servlet/ServletContext.class
jar:file:/G:/mavenRepo/org/apache/tomcat/embed/tomcat-embed-core/9.0.17/tomcat-embed-core-9.0.17.jar!/javax/servlet/ServletContext.class
It was loaded from the following location:
file:/G:/mavenRepo/javax/servlet/servlet-api/2.5/servlet-api-2.5.jar
Action:
Correct the classpath of your application so that it contains a single, compatible version of javax.servlet.ServletContext
经过判断,原因是jar包冲突,从错误信息看出,在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里面引进来的,
tomcat-embed-core-9.0.17.jar是springboot-web引进来,
这就不难看出,问题就是出在这里。
得让其中一个starter不要重复引入servlet-api。考虑到tomcat-embed-core-9.0.17.jar要新一点,于是就告诉
spring-cloud-starter-netflix-eureka-server 不要把servlet-api引进来。
即在pom中修改成:
<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</artifactId> <groupId>javax.servlet</groupId> </exclusion> </exclusions> </dependency>
启动项目,问题解决。
不知道为什么两个会同时引进servlet-api。难道是springboot和eureka的这两个版本选的不合适,如果有猿友懂的,或者研究到这个问题,希望不吝赐教。
更多推荐
所有评论(0)