解决springCloud整合eureka 时,javax.servlet.ServletContext.getVirtualServerName()找不到错误。

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的这两个版本选的不合适,如果有猿友懂的,或者研究到这个问题,希望不吝赐教。

评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值