【问题标题】:Spring's ReloadableResourceBundleMessageSource not finding properties fileSpring 的 ReloadableResourceBundleMessageSource 找不到属性文件
【发布时间】:2012-08-27 18:50:16
【问题描述】:

我在WEB-INF/i18n目录下有两个文件:

  • application.properties
  • messages.properties

我已经正确配置了我的 ReloadableResourceBundleMessageSource bean,如下所示(spring mvc):

<bean class="org.springframework.context.support.ReloadableResourceBundleMessageSource" id="messageSource" p:basenames="WEB-INF/i18n/messages,WEB-INF/i18n/application"
        p:fallbackToSystemLocale="false"/>

但我从 Spring mvc 得到这个:

2012-09-03 02:59:45,911 [http-bio-8080-exec-4] DEBUG org.springframework.context.support.ReloadableResourceBundleMessageSource - Loading properties [application.properties]
2012-09-03 02:59:45,912 [http-bio-8080-exec-4] DEBUG org.springframework.context.support.ReloadableResourceBundleMessageSource - No properties file found for [WEB-INF/i18n/application_fr] - neither plain properties nor XML
2012-09-03 02:59:45,912 [http-bio-8080-exec-4] DEBUG org.springframework.context.support.ReloadableResourceBundleMessageSource - Loading properties [messages.properties]
2012-09-03 02:59:45,912 [http-bio-8080-exec-4] DEBUG org.springframework.context.support.ReloadableResourceBundleMessageSource - No properties file found for [WEB-INF/i18n/messages_fr] - neither plain properties nor XML

谁能给点建议?我可以将属性文件移动到类路径并相应地更改我的配置,但我宁愿了解发生了什么。

【问题讨论】:

    标签: spring spring-mvc spring-roo resourcebundle properties-file


    【解决方案1】:

    在日志消息中它说:application_fr

    注意 _fr。 这意味着它试图寻找 application.properties (application_fr.properties) 的法语版本。 如果它找不到法国属性,它应该回退到默认值(application.properties),所以你的道具应该仍然可以找到。 它寻找法语道具的原因与您应用程序中某处的语言环境设置有关。可能来自浏览器、JVM、应用程序。

    您可以尝试添加以下内容,以强制语言环境为英文:

    <bean class="org.springframework.web.servlet.i18n.FixedLocaleResolver" p:defaultLocale="en"/>   
    

    【讨论】:

    • 感谢锂。正如你所说,它应该回退到application.properties,所以无论我将文件名更改为application_fr.properties还是添加你建议的代码,我仍然得到错误......还有其他想法吗?
    • 这不是错误,而是调试消息。它可能表现正确。您是否发现不正确的属性值?此外,您应该确保 application.properties 无论如何都存在。因此,您可以将 application.properties 复制到 application_fr.properties 。
    • 嗯。我不明白你的意思:另外,你应该确保 application.properties 无论如何都存在。因此,您可以将 application.properties 复制到 application_fr.properties 拥有 application_fr.properties 和 application.properties?我已经试过了......
    猜你喜欢
    • 1970-01-01
    • 2017-02-15
    • 2019-05-10
    • 2014-07-30
    • 2012-02-20
    • 2013-10-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多