2012-01-02 104 views
0

當我使用下面的Spring XML文件類路徑屬性類路徑中的Spring MVC

<bean class="com.fritolay.suppliernet.common.lastresorthandler.impl.SingletonPropertiesRepository"> 
<property name="propertiesFile" value="classpath:ecr/sample.properties" /> 
</bean> 

在這種情況下沒有服務器尋找屬性文件中的應用程序?

我的問題是,我有兩個模塊[1.Web Project 2.Java Project]。我定義的Web項目這個XML文件,並把屬性文件下的Java項目的src folder.But當我部署我的應用我收到以下錯誤:

PropertyAccessException 1: org.springframework.beans.MethodInvocationException: Property 'propertiesFile' threw exception; nested exception is java.io.FileNotFoundException: class path resource [ecr/sample.properties] cannot be resolved to absolute file path because it does not reside in the file system: zip:C:/Oracle/Middleware/user_projects/domains/sample/servers/AdminServer/tmp/_WL_user/_appsdir_supplier-net_ear/6e86rt/sample-service.jar!/ecr/sample.properties 
+0

是'ecr'包中的屬性文件嗎? bean本身是否處理類路徑資源? – 2012-01-02 14:49:12

+0

是的屬性文件在ecr package.Yes中的bean類是它的處理資源文件如下。 public void setPropertiesFile(Resource propertiesFile)throws IOException {this.repository.setPropertiesFiles(Collections.singletonMap( DEFAULT_KEY,propertiesFile)); } – Ran 2012-01-02 14:52:25

+0

您是否檢查過在/ WEB-INF/classes目錄中或在您的類正在打包的JAR文件中部署的屬性文件(如果是)? – 2012-01-02 14:54:17

回答

1

你的Java引擎在這個位置尋找你的文件(在你的錯誤讀):

C:/Oracle/Middleware/user_projects/domains/sample/servers/AdminServer/tmp/_WL_user/_appsdir_supplier-net_ear/6e86rt/sample-service.jar!/ecr/sample.properties 

正如你所看到的,!馬克意味着它正在尋找你的文件的臨時JAR文件中(當然,IDE神器)。

看來您的IDE(或您選擇用於部署的工具)不包括JAR內的屬性文件,因此也是錯誤。 這可能是因爲:

  • 在編譯時,你的工具不是複製這些的recources到 編譯目標目錄(usualy /classes
  • 在包裝的時候,你的JAR建築工具不包括 properties資源放入罐子裏,避開它們。

在這兩種情況下,要解決這個問題,您必須檢查您的構建和部署配置,具體取決於您使用的IDE或工具。

2

如果你有兩個不同的項目,你需要確保當您部署您的網絡項目時,您可以訪問java項目中的代碼。如果你正在以爆炸方式工作,你需要訪問你的java項目從你的web項目,在eclipse中很容易做到。

+0

謝謝,其實我想部署/建立這個應用程序與出eclipse。在日食我知道我們可以很容易'AddProject「依賴 – Ran 2012-01-02 15:04:57

+1

然後,在與春天配置戰鬥之前,測試如果你有**你正在生成(或退出)的jar中的sample.properties **,但是在WEB-INF中的ecr文件夾中。我的eclipse建議是,如果你是以分解的方式工作的話。 – jenaiz 2012-01-02 15:10:43