Fittersman
Fittersman

Reputation: 625

spring - messageSource

org.springframework.context.NoSuchMessageException: No message found under code 'user.username.empty' for locale 'en_GB'.

Currently I have the following code:

applicationContext.xml:

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

What I'm trying to do is cause an error to appear for the user if when they try and register on my site with a blank username, it will give them the error defined as user.username.empty. My application is working as intended and it's looking for the error user.username.empty, however it cannot find it no matter where I put the properties file.

What folder do I need to put the properties file and how do I need it named?

Upvotes: 1

Views: 4234

Answers (1)

JB Nizet
JB Nizet

Reputation: 691715

It must be named messages.properties, and be in the classpath, in the default package. And it must of course contain such a line:

user.username.empty=the message you want

You may customize it for en_GB by using a file named messages_en_GB.properties, in the same location.

Upvotes: 4

Related Questions