问题
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?
回答1:
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.
来源:https://stackoverflow.com/questions/6293157/how-to-change-location-of-validationmessages-properties-in-bean-validation