【问题标题】:Not getting message from resource bundle没有从资源包中获取消息
【发布时间】:2012-04-24 06:15:39
【问题描述】:

我已将 Spring 配置 xml 配置为使用“ResourceBundleMessageSource”,并且我正在尝试从资源包文件中获取消息,但是当我要执行时,我得到的日志显示:找不到资源使用给定名称捆绑。

更精确:

WARN org.springframework.context.support.ResourceBundleMessageSource - ResourceBundle [messages] not found for MessageSource: Can't find bundle for base name messages, locale en_US

我对spring.xml的配置

<bean id="messageSource" class="org.springframework.context.support.ResourceBundleMessageSource">
    <property name="basename">
        <value>messages</value>
    </property>
</bean>

我试图在我的代码中使用的方式:

ResourceBundleMessageSource rbms = (ResourceBundleMessageSource) applicationCtx.getBean("messageSource");
String message = rbms.getMessage("key001", parameters,"default message", null);

还有我的messages.properties的一部分(我已经把这个文件放在project/src/下)

key001 = Problem occurred while fetching the results from database. Please see log.

我也尝试使用 messages_en_US.properites 重命名文件,但没有帮助。

我错过了什么吗?

提前致谢。

【问题讨论】:

    标签: java spring internationalization


    【解决方案1】:

    属性文件在应用程序运行时需要在类路径中;您的 IDE/编译器(和/或 ant/maven 构建过程)是否将 *.properties 复制到“输出”路径?

    如果没有,它需要。 (尝试手动复制开始)

    【讨论】:

      猜你喜欢
      • 2017-05-30
      • 2014-06-16
      • 1970-01-01
      • 2012-07-30
      • 1970-01-01
      • 2018-10-04
      • 2017-08-11
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多