报错:Unable to start ServletWebServerApplicationContext due to missing ServletWebServerFactory

在网上搜了各种方法都没有得到解决,先大概列一下有以下几种说法:

1.没有加@SpringBootApplication注解,我加了,所以不是这个原因

2.没有加@EnableAutoConfiguration注解,加了@SpringBootApplication注解就不需要再加这个注解了,所以也不是这个原因

Springboot Unable to start ServletWebServerApplicationContext due to missing ServletWebServerFactory

一步一步来看:

首先,说我missing ServletWebServerFactory,我点进去,有呀,看着也没什么问题,一切正常;

然后我想到是不是因为默认使用的嵌入式tomcat无法启动,因为我之前把它exclude了

Springboot Unable to start ServletWebServerApplicationContext due to missing ServletWebServerFactory

至于为什么exclude掉呢,是因为我程序中有一个自己写的类HttpServletRequestWrapper继承了HttpServletRequst

Springboot Unable to start ServletWebServerApplicationContext due to missing ServletWebServerFactory

应该继承的是javax.servlet:servlet-api:2.4这个包里的HttpServletRequst,但是由于tomcat-embed-core这个包中也有这个类,同名,当两个Jar包中有同名的类如何选取想要的呢,把想要的包放在前面

Springboot Unable to start ServletWebServerApplicationContext due to missing ServletWebServerFactory

 我把依赖的顺序调整了一下,javax.servlet:servlet-api:2.4放在tomcat-embed-core的前面,但是还是有问题,提示如下:

Springboot Unable to start ServletWebServerApplicationContext due to missing ServletWebServerFactory

从提示中我们可以看出这两个依赖中有重合的地方,且当我把顺序调整以后,如果有同名类,现在先加载的会是servlet-api中的,但是还是不行,必须只能有一个

把servlet-api去掉就好了

相关文章:

  • 2021-12-11
  • 2021-12-13
  • 2021-12-16
  • 2021-07-27
  • 2021-07-01
  • 2022-01-16
  • 2021-05-25
猜你喜欢
  • 2021-12-11
  • 2021-12-30
  • 2018-07-23
  • 2021-12-09
  • 2021-09-15
  • 2021-11-25
相关资源
相似解决方案