SpringBoot项目找不到javax.servlet.Filter的问题

新创建一个SpringBoot项目,编译时出现了找不到javax.servlet.Filter的异常。

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-4kghfwOC-1572270921623)(04-SpringBoot项目找不到javax.servlet.Filter的问题.assets/image-20191028135001016.png)]

这个类位于tomcat-embed这个jar下面,这里的解决方法并不是像网上大部分所说的手动添加这个jar,因为这是由于没有添加spring-boot-starter-web依赖造成的。

springboot项目默认会添加spring-boot-starterspring-boot-starter-test两个依赖,而web项目需要spring-boot-starter-web依赖。

下面对比一下spring-boot-starterspring-boot-starter-web这两个依赖的区别:

spring-boot-starter-web:

在这里插入图片描述

spring-boot-starter,没有web:
在这里插入图片描述

所以在maven里添加下面这个依赖即可:

<dependencies>
  <groupId>org.springframework.boot</groupId>
  <artifactId>spring-boot-starter-web</artifactId>
</dependencies>

猜你喜欢

转载自blog.csdn.net/qq_28379809/article/details/102789716
今日推荐