国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 開發(fā) > Java > 正文

解決maven啟動Spring項目報錯的問題

2024-07-13 10:15:45
字體:
供稿:網(wǎng)友

第一個問題

java.lang.ClassCastException: org.springframework.web.SpringServletContainerInitializer cannot be cast to javax.servlet.ServletContainerInitializer

出現(xiàn)原因主要是 javax.servlet-api 在運行時將spring容器當(dāng)成了servlet容器出現(xiàn)類型轉(zhuǎn)換錯誤。

解決方法:

在pom.xml文件中修改 javax.servlet-api 的作用域為provided

<dependency>   <groupId>javax.servlet</groupId>   <artifactId>javax.servlet-api</artifactId>   <version>3.1.0</version>   <scope>provided</scope>  </dependency>

第二個問題:

Could not resolve bean definition resource pattern [classpath:spring/applicationContext-*.xml]

在SSM項目中,由于有 mapper映射文件和一些其他的配置文件,在maven項目中需要被識別,所以會加上一下配置,允許這些靜態(tài)文件通過,

<resources>   <!-- 如果不添加此節(jié)點mybatis的mapper.xml文件都會被漏掉。 -->   <resource>    <directory>src/main/java</directory>    <includes>     <include>**/*.properties</include>     <include>**/*.xml</include>    </includes>    <filtering>false</filtering>   </resource>

但是以上配置修改了默認(rèn)的resource目錄,導(dǎo)致src/main/resources的所有文件都不能被掃描,也就出現(xiàn)了其他在resources目錄下的文件不能被掃描的錯誤,所以需要加上默認(rèn)的resources 目錄配置:

<build>  <resources>   <!-- 如果不添加此節(jié)點mybatis的mapper.xml文件都會被漏掉。 -->   <resource>    <directory>src/main/java</directory>    <includes>     <include>**/*.properties</include>     <include>**/*.xml</include>    </includes>    <filtering>false</filtering>   </resource>   <resource>    <directory>src/main/resources</directory>    <includes>     <include>**/*.properties</include>     <include>**/*.xml</include>    </includes>    <filtering>false</filtering>   </resource>  </resources> </build> 

以上這篇解決maven啟動Spring項目報錯的問題就是小編分享給大家的全部內(nèi)容了,希望能給大家一個參考,也希望大家多多支持VeVb武林網(wǎng)。


注:相關(guān)教程知識閱讀請移步到JAVA教程頻道。
發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 乌鲁木齐市| 仁化县| 太保市| 高雄市| 建德市| 沽源县| 汉中市| 高州市| 甘孜| 南和县| 自贡市| 咸丰县| 荣成市| 赞皇县| 新邵县| 榕江县| 湘乡市| 郁南县| 内江市| 灌南县| 鸡东县| 甘谷县| 常宁市| 达孜县| 绩溪县| 萝北县| 安康市| 鄢陵县| 砚山县| 西宁市| 清苑县| 新晃| 郯城县| 靖江市| 崇文区| 家居| 新干县| 蓬安县| 尼木县| 民丰县| 隆化县|