无法使用messageSource解析spring消息代码 [英] cannot resolve spring message code using messageSource

查看:386
本文介绍了无法使用messageSource解析spring消息代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在spring中连接一个messageSource以用于我的应用程序。它不起作用,给出了这个错误:

I am trying to hook up a messageSource in spring to use for my application. Its not working, gives this error:


org.springframework.context.NoSuchMessageException:在locale'的代码'validation_required'下找不到消息'。

org.springframework.context.NoSuchMessageException: No message found under code 'validation_required' for locale 'en'.

我的 applicationContext.xml 包含messageSource的def:

my applicationContext.xml contains this def for messageSource:

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

我的消息属性文件位于:

my messages properties file lives in:

/WEB-INF/classes/messages/messages_en_US.properties

最后,我生成错误的调用是:

Finally, the call i made that generates the error is:

String message = messageSource.getMessage("validation_required", null, Locale.ENGLISH);

这个时候有人可以帮我吗?

Can anyone help me at this hour?

推荐答案

问题在于您定义资源包和您指定的语言环境的方式(它们与资源包的搜索顺序。将您的包重命名为messages_en.properties或调用getMessage( ...)使用新的Locale(en,US)。我更喜欢第一个选项。

The problem is with the way you have defined the resource bundle and the locale you are specifying (They doesn't match with the resource bundle's search order. Either rename your bundle to "messages_en.properties" or invoke the "getMessage(...)" with new Locale("en","US"). I prefer the first option.

这篇关于无法使用messageSource解析spring消息代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆