解决IDEA启动springboot项目报错java.lang.ClassNotFoundException: javax.servlet.ServletContext
IDEA启动springboot报错java.lang.ClassNotFoundException: javax.servlet.ServletContext
在IntelliJ IDEA里建了个Maven项目(用的spring boot)创建项目时操作跟之前在eclipse操作步骤基本差不多;
IDEA配置的spring boot项目的tomcat依赖为
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-tomcat</artifactId> <scope>provided</scope> </dependency>
其中<scope>provided</scope>的含义下次单开篇文章详细说明。
启动时报错java.lang.ClassNotFoundException: javax.servlet.ServletContext
后面试了一下,把范围标识 provided 改成 compile ,发现就可以运行了,所以就是 Run Application时,IDEA未加载 provided 范围的依赖包,导致启动时报错(eclipse里面好像默认会加载,所以在那边是能正确运行的)
解决方式
Run ->Edit Configurations
将选项Include dependencies with “Provided” scope勾上。
参考说明:
For the Spring Boot applications, the Include dependencies with “Provided” scope option is enabled by default. (按理说对于Spring-Boot项目默认是启用的,我这默认没启用所以报错)
总结
以上为个人经验,希望能给大家一个参考,也希望大家多多支持脚本之家。
相关文章
SpringData @Query和@Modifying注解原理解析
这篇文章主要介绍了SpringData @Query和@Modifying注解原理解析,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友可以参考下2020-08-08SpringBoot ScheduledTaskRegistrar解决动态定时任务思路详解
本文将从问题出发,详细介绍ScheduledTaskRegistrar类是如何解决动态调整定时任务的思路,并给出关键的代码示例,帮助大家快速地上手学习2023-02-02
最新评论