将文件放在WEB-INF目录下并读取它们



我们正在使用JBOSS 5.1.0。遗传算法和弹簧集成框架。我们将配置文件放在JBOSS的conf目录下,以便从类路径中读取它们。但是现在我们被告知,我们应该将所有的配置文件从conf目录移动到war文件的WEB-INF目录。当我们将文件放在conf目录下时,一切都工作正常。

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

但是,当我们通过以下更改将配置文件从conf目录移动到WEB-INF目录时,我们得到了例外java.io.FileNotFoundException

<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)

有人知道该怎么做吗?

将它们放置在类路径中(通过某些构建方法)。

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

WEB-INF目录路径在独立的Spring项目中将不能作为类路径使用。因此,我已经将配置文件移动到src/resources文件夹,以便导入它们,没有任何麻烦。

最新更新