2017-08-12 81 views
0

我試圖使用PropertiesFactoryBean從特定目錄加載以.prop結尾的所有文件。Spring PropertiesFactoryBean通配符擴展不起作用

<bean id="props" class="org.springframework.beans.factory.config.PropertiesFactoryBean"> 
    <property name="location" value="file:/etc/app/*.prop"/> 
</bean> 

運行此作爲JUnit測試,everyting工作的所有文件確定,org.springframework.core.io.support.PropertiesLoaderSupport#loadProperties獲取列表(通配符展開)爲FileSystemResource 並加載它們。

但是,當在OS​​GI環境(卡拉夫)PropertiesLoaderSupport#loadProperties運行將獲得單一的OsgiBundleResource與路徑設置爲/etc/app/*.prop,當然這是無效的。

回答

0

嘗試使用locations屬性,而不是location(僅支持一個資源)

<bean id="props" class="org.springframework.beans.factory.config.PropertiesFactoryBean"> 
    <property name="locations" value="file:/etc/app/*.prop"/> 
</bean>