Spring Junit 測試 porperties 配置沒法加載

<!--正確-->
<context:property-placeholder location="classpath*:*.properties"/>
<!--錯誤-->
<context:property-placeholder location="classpath:*.properties"/>

classpath:與classpath*:的區別在於, 

前者只會從第一個classpath中加載,而 後者會從全部的classpath中加載  
若是要加載的資源, 不在當前ClassLoader的路徑裏,那麼用classpath:前綴是找不到的, 
這種狀況下就須要使用classpath*:前綴 
在多個classpath中存在同名資源,都須要加載, 
那麼用classpath:只會加載第一個,這種狀況下也須要用classpath*:前綴 
 spa

相關文章
相關標籤/搜索