启动SpringBoot项目找不到报错java.lang.ClassNotFoundException: javax.servlet.Filter。

出现该问题是因为缺少javax.servlet.Filter的Tomcat-embed-core-xxx.jar包;我们通常使用 spring-boot-starter-web 注入即可。

启动设置找不到spring boot spring-boot-starter-web 找不到_spring

但是我检查了maven本地仓库中已经有,且项目依赖maven中也存在该包;pom文件也注入了spring-boot-starter-web;编译也通过不报错。但是就是项目启动报错。

经过一番折腾,我仔细对比了pom文件的配置项内容,发现有细小差异;

这是我配置的(有问题的):

<dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-tomcat</artifactId>
            <scope>provided</scope>
</dependency>

正确的配置(在远程maven仓库中搜索的配置):

<dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-tomcat</artifactId>
            <version>2.3.1.RELEASE</version>
 </dependency>

启动设置找不到spring boot spring-boot-starter-web 找不到_spring_02

经过对比,发现 <scope>provided</scope> 是导致报错的根源;所以直接删除这个属性;添加版本号属性,重启错误得到解决。