国产探花免费观看_亚洲丰满少妇自慰呻吟_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ā)表
主站蜘蛛池模板: 修武县| 泽库县| 定日县| 鹤峰县| 安陆市| 昌邑市| 天祝| 永川市| 二连浩特市| 龙井市| 资阳市| 宜兴市| 衡阳县| 贵定县| 安西县| 南昌市| 同江市| 同江市| 五河县| 绥中县| 尚义县| 衡南县| 同德县| 永嘉县| 筠连县| 广平县| 綦江县| 安西县| 乌兰察布市| 化德县| 东阿县| 凤翔县| 阳原县| 平原县| 瑞金市| 宜丰县| 汉沽区| 黑水县| 临朐县| 阜新| 红原县|