spring - messageSource

时间:2012-01-24 11:07:57

标签: spring-mvc

  

org.springframework.context.NoSuchMessageException:在代码'user.username.empty'下找不到区域设置'en_GB'的消息。

目前我有以下代码:

applicationContext.xml

<bean id="messageSource"
      class="org.springframework.context.support.ResourceBundleMessageSource"
      p:basename="messages" />

我要做的是导致用户出现错误,如果他们尝试使用空白用户名在我的网站上注册,则会向他们提供定义为user.username.empty的错误。我的应用程序正在按预期工作,它正在查找错误user.username.empty,但无论我将属性文件放在何处都无法找到它。

我需要在什么文件夹中放置属性文件?如何命名?

1 个答案:

答案 0 :(得分:4)

它必须命名为messages.properties,并且位于默认包中的类路径中。它必须包含这样一条线:

user.username.empty=the message you want

您可以在同一位置使用名为en_GB的文件为messages_en_GB.properties自定义。