解決 java.io.FileNotFoundException: class path resource [applicationContext.xml] cannot be opened because it does not exist


前幾天好好運行的web項目突然跑不起來了

報這個錯誤

2019-09-16 19:18:29  [ RMI TCP Connection(3)-127.0.0.1:357 ] - [ ERROR ]  Context initialization failed

org.springframework.beans.factory.BeanDefinitionStoreException: IOException parsing XML document from class path resource [applicationContext.xml]; nested exception is java.io.FileNotFoundException: class path resource [applicationContext.xml] cannot be opened because it does not exist

很顯然,是找不到配置文件。

1、先考慮recourse目錄下的配置文件路徑是否正確。

  點擊文件名可以跳轉,排除這個原因。

2、檢查生成的target/classes 文件下是否有配置文件。

  這是輸出目錄的主體,項目實際使用的配置文件就在里面。

  

 

沒有找到配置文件。

 解決辦法:在pom.xml中添加下面代碼

<build>
        <resources>
            <resource>
                <directory>src/main/recourse</directory>
                <includes>
                    <include>**/*.xml</include>
                    <include>**/*.properties</include>
                </includes>
                <filtering>true</filtering>
            </resource>
        </resources>
    </build>
<directory></directory>路徑根據自己的配置文件的路徑而定。
<includes></includes>中的內容根據自己配置文件的種類而定。

 

 成功。

 

參考博客:

https://blog.csdn.net/moneyshi/article/details/53287036

https://blog.csdn.net/yyym520/article/details/80516103

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM