2016-08-18 73 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文件夹下的配置文件。我对么? –

相关问题