如何在Bean验证中更改ValidationMessages.properties的位置 [英] How to change location of ValidationMessages.properties in Bean Validation

查看:718
本文介绍了如何在Bean验证中更改ValidationMessages.properties的位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

默认情况下,ValidationMessages.properties可以位于我的类路径的根目录中.是否可以更改com.myapp.Anything.properties之类的文件的位置?

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?

推荐答案

根据JSR-303规范:

From the JSR-303 specification:

4.3.1.1.默认消息插值算法默认消息插值器使用以下步骤:

4.3.1.1. Default message interpolation algorithm The default message interpolator uses the following steps:

  1. 消息参数是从消息字符串中提取的,并用作搜索名为ValidationMessages的ResourceBundle的键(通常是 体现为属性文件/ValidationMessages.properties和 (其语言环境的变化)使用定义的语言环境(请参见下文).如果一个 找到属性,将message参数替换为 消息字符串中的属性值.递归应用步骤1 直到没有替换为止(即消息参数值 本身可以包含message参数.
  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).

这似乎是默认设置和建议.为了对此进行备份,JSR-303 TCK使用TestNG将它们移动到与资源类路径上的"./"相同的"WEB-INF/classes/"目录.

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

对不起.

这篇关于如何在Bean验证中更改ValidationMessages.properties的位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆