0

I am using a CustomDateEditor to parse date-time values submitted as form values, and set up a ValidationMessages.properties properties file to provide the message text for validation failures. But Spring is still displaying the default ugly IllegalArgumentException message instead of the message text I've provided. What have I done wrong?

Raedwald
  • 46,613
  • 43
  • 151
  • 237
  • I am answering my own question, [as is encouraged](http://stackoverflow.com/help/self-answer). – Raedwald Mar 07 '14 at 11:18
  • See also http://stackoverflow.com/questions/13314862/spring-validations-default-messages : in that question the user did not use the normal name for the messages properties file (`ValidationMessages.properties`), so in that case it is clearer that you must tell Spring which properties file to use. – Raedwald Mar 07 '14 at 11:22

1 Answers1

0

Although ValidationMessages.properties is the normal location for validation messages, Spring does not load the messages from there by default. You must explicitly tell Spring to load those message, using a ResourceBundleMessageSource object. That is, with a bean definition like this:

 <bean class="org.springframework.context.support.ResourceBundleMessageSource" id="messageSource">
    <property name="basenames">
       <list>
          <value>ValidationMessages</value>
       </list>
    </property>
 </bean>
Raedwald
  • 46,613
  • 43
  • 151
  • 237