2016-08-18 74 views
0

我們使用JBOSS 5.1.0.GA和spring集成框架。我們將配置文件放在JBOSS的conf目錄下,以便從類路徑中讀取它們。但是現在我們被告知我們應該將所有配置文件從conf目錄移動到war文件的WEB-INF目錄。一切工作正常當我們把文件放在conf目錄下。將文件放在WEB-INF目錄下並閱讀它們

<bean id="xyz" class="org.springframework.beans.factory.config.PropertiesFactoryBean"> 
     <property name="locations"> 
      <list> 
       <value>classpath:CustomerService/property-files/*.properties</value>  
      </list> 
     </property> 
</bean> 

但是,當我們通過以下的改變,我們所得到的異常java.io.FileNotFoundExceptionconf目錄移動配置文件以WEB-INF目錄。

<bean id="xyz" class="org.springframework.beans.factory.config.PropertiesFactoryBean"> 
     <property name="locations"> 
      <list> 
       <value>/WEB-INF/CustomerService/property-files/*.properties</value>  
      </list> 
     </property> 
</bean> 

異常的詳細信息:

java.io.FileNotFoundException: URL [jndi:/localhost/pqawdTestWebApp/WEB-INF/CustomerService/spring-integration/Jobs/] cannot be resolved to absolute file path because it does not reside in the file system: jndi:/localhost/pqawdTestWebApp/WEB-INF/CustomerService/spring-integration/Jobs/ 
    at org.springframework.util.ResourceUtils.getFile(ResourceUtils.java:205) 
    at org.springframework.core.io.AbstractFileResolvingResource.getFile(AbstractFileResolvingResource.java:52) 
    at org.springframework.core.io.UrlResource.getFile(UrlResource.java:169) 
    at org.springframework.core.io.support.PathMatchingResourcePatternResolver.doFindPathMatchingFileResources(PathMatchingResourcePatternResolver.java:526) 

任何人有做什麼想法?

回答

0

WEB-INF目錄路徑在獨立的Spring項目中將不可用作類路徑。所以,我已經將配置文件移到了src/resources文件夾中,無需任何麻煩地導入它們。

0

將它們放在類路徑中(通過一些構建方法)。

/WEB-INF/classes/CustomerService/property-files/*.properties 
+0

沒關係。但是如何從web.xml和其他spring配置文件中讀取它們呢?我們需要指定那裏讀取什麼路徑? –

+0

如前所述,'classpath:CustomerService/property-files/...'(在spring中)。剩下的就是普通的資源文件,'getResourceAsStream(「/ ...」)'或其他什麼, –

+0

這意味着我們需要一個spring bean來讀取WEB-INF文件夾下的配置文件。我對麼? –

相關問題