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

标签 java spring properties internationalization resourcebundle

我有一个 Spring 项目。我为不同的模块创建了不同的属性文件,这些文件位于各自的目录中。

例如,在“资源”文件夹中,我有“学生”和“教师”文件夹。在学生文件夹中,我有student_en.properties,在教师文件夹中,我有teacher_en.properties。现在我如何在 spring 中配置它,以便我可以使用“ReloadableResourceBundleMessageSource”或任何其他 bean 从所有文件中获取区域设置特定属性。

现在是 -

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

我可以使用正则表达式或以某种方式在资源文件夹的所有子目录中包含属性文件吗?

最佳答案

Basenames 接受数组作为参数:

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

关于java - Spring中从多个属性文件读取资源,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21267779/

相关文章:

java - 触摸事件 : I want to recognize touches while moving with an another finger on the screen

java - 无法使用spring boot从另一台服务器连接rabbitmq

java - 加载 Java .properties 文件,获取 java.util.MissingResourceException : Can't find bundle for base name what am I doing wrong?

powershell - 使用 PowerShell 复制右键单击文件夹并选择属性

c# - 在自己的构造函数中初始化一个新类

c# - 如何在没有JIT的情况下运行程序?

java - 如何构建在线编译器而不在我自己的服务器上编译代码

Java 10 var 和捕获变量

spring - 在 Spring 和 Vaadin 中使用 ViewAccessControl

spring - DispatcherServletAutoConfiguration 因 tomcat 而失败