IDEA中Spring配置錯誤:class path resource [.xml] cannot be opened because it does not exist


IDEA中Spring配置錯誤:class path resource [.xml] cannot be opened because it does not exist

運行 Spring 項目時出現類似下面的錯誤信息

 class path resource [applicationContext.xml] cannot be opened because it does not exist

翻譯:沒有找到你的 .xml 配置文件

原因

在Test測試類中我使用的是:

 ApplicationContext ctx = new ClassPathXmlApplicationContext("applicationContext.xml");

獲取配置文件。

ClassPathXmlApplicationContext()方法是在其所在的目錄中尋找 .xml 配置文件。

注意: 這里指的是編譯后的 .class 文件所在的目錄,不是 .java 文件

解決

點擊 File -> Project Structure,選擇Modules -> Paths -> Output Paths
修改為 applicationContext.xml 文件所在目錄。


免責聲明!

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



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