解決IDEA啟動springboot項目報錯java.lang.ClassNotFoundException:?javax.servlet.ServletContext
IDEA啟動springboot報錯java.lang.ClassNotFoundException: javax.servlet.ServletContext
在IntelliJ IDEA里建了個Maven項目(用的spring boot)創(chuàng)建項目時操作跟之前在eclipse操作步驟基本差不多;
IDEA配置的spring boot項目的tomcat依賴為
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-tomcat</artifactId> <scope>provided</scope> </dependency>
其中<scope>provided</scope>的含義下次單開篇文章詳細(xì)說明。
啟動時報錯java.lang.ClassNotFoundException: javax.servlet.ServletContext
后面試了一下,把范圍標(biāo)識 provided 改成 compile ,發(fā)現(xiàn)就可以運行了,所以就是 Run Application時,IDEA未加載 provided 范圍的依賴包,導(dǎo)致啟動時報錯(eclipse里面好像默認(rèn)會加載,所以在那邊是能正確運行的)
解決方式
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項目默認(rèn)是啟用的,我這默認(rèn)沒啟用所以報錯)
總結(jié)
以上為個人經(jīng)驗,希望能給大家一個參考,也希望大家多多支持腳本之家。
- SpringBoot集成WebServlet出現(xiàn)自定義servlet請求失敗的問題解決方案
- SpringBoot里使用Servlet進(jìn)行請求的實現(xiàn)示例
- springboot掃描自定義的servlet和filter代碼詳解
- Springboot注入成員變量HttpServletRequest的原理分析
- SpringBoot3.1.2 引入Swagger報錯Type javax.servlet.http.HttpServletRequest not present解決辦法
- SpringBoot獲取HttpServletRequest的3種方式總結(jié)
- Springboot如何添加server.servlet.context-path相關(guān)使用
- SpringBoot項目找不到j(luò)avax.servlet.Filter的問題及解決
- SpringBoot如何切換成其它的嵌入式Servlet容器(Jetty和Undertow)
相關(guān)文章
Maven繼承父工程時的relativePath標(biāo)簽解析用法小結(jié)
relativePath 的作用是為了找到父級工程的pom.xml,本文主要介紹了Maven繼承父工程時的relativePath標(biāo)簽解析用法小結(jié),具有一定的參考價值,感興趣的可以了解一下2024-03-03Spring?Cloud?整合?nacos實現(xiàn)動態(tài)配置中心的詳細(xì)步驟
這篇文章主要介紹了Spring?Cloud?整合?nacos?實現(xiàn)動態(tài)配置中心,整合步驟是通過添加依賴新建nacos配置,本文分步驟通過實例代碼給大家詳細(xì)講解,需要的朋友可以參考下2022-10-10Spring Boot使用Value注解給靜態(tài)變量賦值的方法
這篇文章主要介紹了Spring Boot使用Value注解給靜態(tài)變量賦值的方法,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2018-07-07mybatis3中@SelectProvider傳遞參數(shù)方式
這篇文章主要介紹了mybatis3中@SelectProvider傳遞參數(shù)方式。具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教2021-08-08