简体   繁体   English

在Spring中从多个属性文件读取资源

[英]Read resources from multiple properties files in Spring

I have a spring project. 我有一个春季项目。 I have created different properties files for different modules and these files are in their respective directories. 我为不同的模块创建了不同的属性文件,这些文件位于各自的目录中。

For example, in "resources" folder, I have "student" and "teacher" folders. 例如,在“资源”文件夹中,我有“学生”和“老师”文件夹。 In student folder, I have student_en.properties and in teacher folder, I have teacher_en.properties. 在学生文件夹中,我有student_en.properties,在教师文件夹中,我有teacher_en.properties。 Now how do I configure it in spring so that I can get locale specific properties from all files using "ReloadableResourceBundleMessageSource" or any other bean. 现在,如何在春季配置它,以便可以使用“ ReloadableResourceBundleMessageSource”或任何其他bean从所有文件中获取特定于语言环境的属性。

Right now, it is - 现在是-

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

Can I use regex or somehow include property files in all sub-directories of resources folder? 我可以使用正则表达式还是以某种方式在资源文件夹的所有子目录中包含属性文件?

Basenames accepts array as a parameter: 基本名称接受数组作为参数:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM