Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/spring-mvc/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
未从属性文件中拾取Spring mvc验证错误_Spring_Spring Mvc_Bean Validation - Fatal编程技术网

未从属性文件中拾取Spring mvc验证错误

未从属性文件中拾取Spring mvc验证错误,spring,spring-mvc,bean-validation,Spring,Spring Mvc,Bean Validation,使用SpringMVC内置JSR303Bean验证及其工作正常(只有一个问题除外),不会从属性文件中提取消息 我的Web应用程序是用maven创建的,这是当前的结构 Main -java -resources -bundles -message.properties -webapp PersistableCustomer extends SecuredCustomer SecuredCustomer extends

使用SpringMVC内置JSR303Bean验证及其工作正常(只有一个问题除外),不会从属性文件中提取消息

我的Web应用程序是用maven创建的,这是当前的结构

Main
      -java
      -resources
         -bundles
            -message.properties
      -webapp
PersistableCustomer extends SecuredCustomer
SecuredCustomer extends CustomerEntity
XML文件 在我的JSP页面上,我得到了这些消息
这个字段是必需的
,不确定是什么问题 我的数据类具有以下结构

Main
      -java
      -resources
         -bundles
            -message.properties
      -webapp
PersistableCustomer extends SecuredCustomer
SecuredCustomer extends CustomerEntity

即使在将消息源传递给验证器之后,它也不会从自定义属性文件中提取消息。

我在这里胡乱猜测。。。通常,JSR-303消息插入器从
ValidationMessages.properties
获取消息。如果希望验证器使用Spring的消息源,则需要以这种方式进行配置:

<bean id="validator" class="org.springframework.validation.beanvalidation.LocalValidatorFactoryBean">
    <property name="validationMessageSource" ref="messageSource" />
</bean>

<mvc:annotation-driven validator="validator" />


您的
消息名中缺少
s
。属性
。但我认为这只是问题中的一个输入错误,对吗?@PavelHoral:这是一个输入错误:)看一看,情况是一样的。@JakubJirutka:我没有使用任何自定义验证器,只使用out-of提供的验证box@UmeshAwasthi这与此无关,关键是您使用的是非默认消息源。相信我,试试我的解决方案,它会奏效的这没有帮助..即使按照建议设置..它仍然选择默认值显示您的MVC基础结构定义了吗?您是只使用
还是有更细粒度的配置?您可能需要使用验证器定义web绑定初始值设定项。我正在使用
,用所需的详细信息更新我的帖子。请看一下更新我的答案。。。您可以在
元素上设置
验证程序
引用。我仍然面临奇怪的问题..虽然绑定结果显示正确的错误,但仍然在jsp上显示相同的默认消息
PersistableCustomer extends SecuredCustomer
SecuredCustomer extends CustomerEntity
<bean id="validator" class="org.springframework.validation.beanvalidation.LocalValidatorFactoryBean">
    <property name="validationMessageSource" ref="messageSource" />
</bean>

<mvc:annotation-driven validator="validator" />