問題如下:原先運行正常的項目,突然在applicationContext.xml 文件頭報錯
Referenced file contains errors (http://www.springframework.org/schema/context/spring-context.xsd). For more information, right click on the message in the Problems View and select "Show Details..."
原因分析:如果使用Maven構建項目,spring在加載xsd文件時總是先試圖在本地查找xsd文件(spring的jar包中已經包含了所有版本的xsd文件),如果沒有找到,才會轉向去URL指定的路徑下載。所以出現該情況一般是因為斷網或spring的官網暫時無法連接導致的。 可以通過在瀏覽器輸入xsd文件的URL,如:spring-beans的話,輸入http://www.springframework.org/schema/beans/spring-beans-2.0.xsd 進行確認。
這次項目我是使用Maven。
解決辦法:1. 首先為了確保 Eclipse 可以從遠程拿到 xsd 文件,到 Window -> Preferences -> General -> Network Connections -> Cache 下的 Cache entries 框內檢查所需要的文件是否正確,如果不確定,就點擊 "Remove All",然后右擊當前的 Project 選擇 Validator,Eclipse 會重新加載 xsd 文件;
2.最簡捷的方法是刪掉 xsd 文件的版本號(我的項目所有的都已經刪除了,但仍報錯,故采取method 1)。