2014-01-21 117 views
0

我有一個spring項目。我爲不同的模塊創建了不同的屬性文件,這些文件位於各自的目錄中。從Spring中的多個屬性文件中讀取資源

例如,在「資源」文件夾中,我有「學生」和「教師」文件夾。在學生文件夾中,我有student_en.properties,並且在教師文件夾中,我有teacher_en.properties。現在我如何在春季配置它,以便使用「ReloadableResourceBundleMessageSource」或任何其他bean從所有文件中獲取特定於語言環境的屬性。

現在,它是 -

<bean id="messageSource" 
    class="org.springframework.context.support.ReloadableResourceBundleMessageSource"> 
    <property name="basenames" 
     value="classpath:messages" /> 
</bean> 

我可以使用正則表達式或以某種方式包括在資源文件夾的所有子目錄的屬性文件?

回答

1

基本名稱接受數組作爲參數:

<bean id="messageSource" 
    class="org.springframework.context.support.ReloadableResourceBundleMessageSource"> 
    <property name="basenames"> 
     <util:list> 
     <value>classpath:student/student</value> 
     <value>classpath:teacher/teacher</value> 
     </util:list> 
    </property> 
</bean> 
+0

不過是我的子目錄類路徑?另外,如果我必須支持20種語言,那麼我需要在中包含20 * 2 = 40行? –

+0

對不起,我已經解決了我的問題。正如我記得你應該添加目錄,因爲它像包一樣工作。你不必包含語言 –