I'm using Spring 3.0.5-RELEASE, with JSR-303 style validation and Hibernate validator 4.1.0-Final. My model class looks something like this:
public class Model {
@Max(value=10,message="give a lower value")
Integer n;
}
And this is passed as request param in a spring mvc servlet with binding. So the request would look something like this:
http://localhost:8080/path?n=10
What I want is to be able to customize the error message when there is a type mismatch exception, e.g.
http://localhost:8080/path?n=somestring
Which results in a very long default message that I want to replace.
I've tried just about every configuration described on the web and none of them seem to work. Does someone know what the right configuration is?
Specifically, what do I need in my mvc-servlet.xml? What do I need in my messages.properties file? Does the message.properties file have a magic name so that hibernate-validator will find it?
I've used the following in my mvc-servlet.xml without success:
<bean id="messageSource" class="org.springframework.context.support.ReloadableResourceBundleMessageSource" p:basename="messages" />
And a messages.properties file at src/main/resources (and also at src/main/webapp/WEB-INF)...
I've tried all sorts of combinations in messages.properties even for doing simple override of say @NotEmpty messages and even that doesn't work for me.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…