参考网上的说明: 死活弄不出占位符不起作用。难道spring 和hibernate有仇?最后参考hibernate validator管网,使用如下配置,成功了。
spring 配置如下:
<!-- 配置fastjson的注解驱动,自动注入了支持JSR303..校验的类 -->
<mvc:annotation-driven validator="validator"> <!-- fastjson的支持类 --> <mvc:message-converters register-defaults="true"> <bean id="fastJsonHttpMessageConverter" class="com.alibaba.fastjson.support.spring.FastJsonHttpMessageConverter"> <property name="supportedMediaTypes" value="application/json"/> <property name="features"> <list> <value>QuoteFieldNames</value> </list> </property> </bean> </mvc:message-converters> </mvc:annotation-driven><!-- 以下 validator ConversionService 在使用 mvc:annotation-driven 会 自动注册-->
<bean id="validator" class="org.springframework.validation.beanvalidation.LocalValidatorFactoryBean"> <property name="messageInterpolator" ref="messageInterpolator"/> <property name="providerClass" value="org.hibernate.validator.HibernateValidator"/> </bean> <bean id="messageInterpolator" class="org.hibernate.validator.messageinterpolation.ResourceBundleMessageInterpolator"> <constructor-arg name="userResourceBundleLocator" index="0" ref="userResourceBundleLocator"/> <constructor-arg name="cacheMessages" value="true"/> </bean> <bean id="userResourceBundleLocator" class="org.hibernate.validator.resourceloading.PlatformResourceBundleLocator"> <constructor-arg name="bundleName" value="i18n.User"/> </bean>