1. 程式人生 > >Spring+Data+JPA持久層的使用及注意事項(三)——Failed to load ApplicationContext無法載入配置檔案

Spring+Data+JPA持久層的使用及注意事項(三)——Failed to load ApplicationContext無法載入配置檔案

Failed to load ApplicationContext這個問題是有很多的,我的檢查過程是這樣:

1,檢查web.xml中對於spring的listener的配置是否有問題,因為我這是一鍵生成的,所以主要是看路徑問題,也就是location有沒有配對

    <!-- needed for ContextLoaderListener -->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>location</param-value>
</context-param>
<!-- Bootstraps the root web application context before servlet initialization -->
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>

</listener>

2,是要檢查繼承問題,在maven專案中專案之間的繼承和引用是非常重要的一部分,就像是一個環一樣,少一個點就可能造成專案中的許多功能無法實現,也就是檢查pom.xml有沒有出現配置出錯的地方

3,是要檢查類中在引用路徑有沒有出錯,比如在測試類的引用中也是用到了applicationContext.xml的路徑的引用:、

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration("classpath:applicationContext.xml")

public class StandardDaoTest {}

4,前面都是一些基本的檢查,如果之前執行過applicationContext.xml則前面的一些可以直接不用檢查而進行如下細緻的去檢查,比方說配置檔案中的某項配置是否出現問題,這個通常會在報錯中給提示出來;

5,就是在applicationContext.xml掃描的各個類或者包中去檢查了,檢視註解是否出現問題。