maven創建spring項目報錯
Exception in thread “main” 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
applicationContext.xml是放在src目錄下的,
ApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml"); 進行讀取
讀取不到的原因是根據當前路徑進行尋找,File->Project Structure->Modules可以看到Source Folders是不包含src的,所以讀取不到。
解決方案:
1、將src添加到Source Folders。
2、利用FileSystemXmlApplicationContext
ApplicationContext context = new FileSystemXmlApplicationContext("src/applicationContext.xml");