By default, ValidationMessages.properties can be located in root of my classpath. Can I change the location of this file like com.myapp.Anything.properties?
Asked
Active
Viewed 5,677 times
10
-
2You can use Spring's [LocalValidatorFactoryBean.setValidationMessageSource()](http://docs.spring.io/spring/docs/current/javadoc-api/org/springframework/validation/beanvalidation/LocalValidatorFactoryBean.html#setValidationMessageSource-org.springframework.context.MessageSource-) method. Take a look at [this question](http://stackoverflow.com/questions/28492763/spring-boot-jsr303-message-code-in-annotation-getting-ignored). Or if you don't want to use Spring you may use the same technique (look at the source code of LocalValidatorFactoryBean) – Ilya Serbis Sep 23 '15 at 11:42
1 Answers
2
From the JSR-303 specification:
4.3.1.1. Default message interpolation algorithm The default message interpolator uses the following steps:
- Message parameters are extracted from the message string and used as keys to search the ResourceBundle named ValidationMessages (often materialized as the property file /ValidationMessages.properties and its locale variations) using the defined locale (see below). If a property is found, the message parameter is re- placed with the property value in the message string. Step 1 is applied recursively until no replacement is per- formed (i.e. a message parameter value can itself contain a message parameter).
It seems that this is the default and the suggestion. To back this up the JSR-303 TCK uses TestNG to move them to the "WEB-INF/classes/" directory which is the same as "./" on the resources classpath.
(You can experiment with it but that's about all I can figure out.)
Sorry.

Chris Ruffalo
- 1,903
- 12
- 17