How to change location of ValidationMessages.properties in Bean Validation

二次信任 提交于 2019-12-10 12:39:13

问题


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:

  1. 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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!